Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to design a API where a request is made to the URL and in turn return a response.
Now i do not want to use any framework as such.
So my question is how can i make this happen.I want to send a request from the web browser and get the response.I have the apache server setup.So where should my python code leave to receive the request and how to respond back
EDIT
import urllib2
request = urllib2.Request('http://localhost/')
request.get_method = lambda : 'HEAD'
response = urllib2.urlopen(request)
response.info().gettype()
Try Flask, it's a microframework and setting it up should be a one-liner.
http://flask.pocoo.org/
Here're the docs for configuring Apache to run it:
http://flask.pocoo.org/docs/deploying/mod_wsgi/
I know you said no frameworks, but this is a lot more simple than doing it yourself.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
I would like to create a bot that sends a request (post) via a command /refresh with certain information so where I say /refresh test and it then sends a POST with certain information that is given for the time being.
Like this
client_id=CLIENT_ID_HERE&client_secret=CLIENT_SECRET_HERE&refresh_token=REFRESH_TOKEN_HERE&grant_type=refresh_token&redirect_uri=REDIRECT_URI_HERE
but don't know how.
So I reread this now many times. If I understood it right now, you just want to post something to, for example https://example.com/post
If so, then use aiohttp and create a client session and post it.
import aiohttp
#this in your command
async with aiohttp.ClientSession() as session:
await session.post(“https://example.org/post“, data={“foo”:”bar”})
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to make a simple post method with the requests module, like this :
s=requests.Session()
s.post(link,data=payload)
In order to do it properly, the payload is an id from the page itself, and it's generated in every access to the page.
So I need to POST without reloading the entire webpage so i can get the right id .
Is this code in a view?
If yes, I'd advise you to create an Ajax view receiving this POST and send the payload from the page using javascript as Ajax.
This way on success, you can get the right id in the response of that view without reloading the page.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm new to Flask but have experience with PHP. I know there are session variables and global variables just as in PHP, but what do the contexts actually mean? I read the documentation but could not understand whet it was saying.
What are the application and request contexts, and what the is app.app_context()?
app.app_context loads the application and any extentions you have loaded.
A request context is loaded when you are dealing with a request.
A good example.
If you have a background cron that does some database work, you'll need to make use of app_context to get access to the models.
You'll be a in request context pretty much whenever you're handling a view.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am learning Flask and I want to practice by making simple web app.
I want to make a chat web app that allows sending messages between two or more web browsers in Flask but I am not sure where to start or go about building this application. This question is pretty broad but what I want to know is how to structure this application. What are the pieces I need to build this application.
very broad question, but I'd recommend starting here with web sockets http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent . Then you can have two member subscribe to a channel and make messages to each other.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there a Python program where you can post a status update without going to the website itself?
Where or how do i get started?
You would wanna get started here, https://github.com/facebook/python-sdk
unless there's a library I don't know about.
You can checkout my fork of the python sdk. It's customized to work better with django.
You can check here on how to use it to authenticate a user.
After that you can use the python sdk to post a news entry.
fb.put_wall_post("hello")
Or do it yourself, it's only a matter of doing a POST request to http://graph.facebook.com/FBID/feed where FBID is the ID of the page or profile you want to publish to, more info in the facebook doc.