Python and POST data

In PHP I simply write:

$bob = $_POST['bob'];

How do I do the same in Python?

And yes, I do normally check that it exists etc, I'm just stripping it down specifically to the functionality I am after.


Edit: I am not using a framework


Asked by: Daryl867 | Posted: 27-01-2022






Answer 1

The simplest method is the 'cgi' module:

import cgi
data = cgi.FieldStorage()
data['bob']

But the context you are executing in (frameworks you're using, WSGI or even (heaven forbid) mod_python) may have different, more efficient or more direct methods of access.

Answered by: Chloe997 | Posted: 28-02-2022



Similar questions

Http POST Curl in python

I'm having trouble understanding how to issue an HTTP POST request using curl from inside of python. I'm tying to post to facebook open graph. Here is the example they give which I'd like to replicate exactly in python. curl -F 'access_token=...' \ -F 'message=Hello, Arjun. I like this new API.' \ https://graph.facebook.com/arjun/feed Can anyone help me understand this?


HTTP POST in Python

I am trying to convert a HTTP POST into Python and am not sure how to go about doing this. I have the HTTP Request: POST vision/v1/ocr?language=unk&detectOrientation =true Content-Type: application/json Host: api.projectoxford.ai Content-Length: 95 Ocp-Apim-Subscription-Key: •••••••••••••••••••••••••••••••• { "Url": "exampleurl.com"} As well as the URL request and need help on...


c# - Http Post data from Python to net core app

I am trying to send a file from a Python script to my .net core webserver. In Python I am doing this using the requests library, and my code looks like so. filePath = "run-1.csv" with open(filePath, "rb") as postFile: file_dict = {filePath: postFile} response = requests.post(server_path + "/batchUpload/create", files=fi...


Is there any way to do HTTP PUT in python

I need to upload some data to a server using HTTP PUT in python. From my brief reading of the urllib2 docs, it only does HTTP POST. Is there any way to do an HTTP PUT in python?


Python 3 Get HTTP page

How can I get python to get the contents of an HTTP page? So far all I have is the request and I have imported http.client.


http - How come my python code doesn't work?

def getSize(f): print StringIO(f) im = Image.open(StringIO(f)) size = im.size[0], im.size[1] return size def download(source_url, g = False, correct_url = True): try: socket.setdefaulttimeout(10) agents = ['Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)','Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)','Microsoft Internet Explorer/4.0b1 (Windows 95)','Opera/8.00 (Window...


Http POST Curl in python

I'm having trouble understanding how to issue an HTTP POST request using curl from inside of python. I'm tying to post to facebook open graph. Here is the example they give which I'd like to replicate exactly in python. curl -F 'access_token=...' \ -F 'message=Hello, Arjun. I like this new API.' \ https://graph.facebook.com/arjun/feed Can anyone help me understand this?


http - Python str to file type

I'm downloading an image with the requests library and then writing the image to disk, then reopening the new file to pass on into another function. if __name__ == '__main__': r = requests.get(IMAGE_STREAM, stream=True) output = StringIO.StringIO() with open('1.jpg', 'wb') as f: f.write(r.content) f = open('1.jpg') img = Image.open(f) Is there a method where I can skip the writing and...


HTTP POST in Python

I am trying to convert a HTTP POST into Python and am not sure how to go about doing this. I have the HTTP Request: POST vision/v1/ocr?language=unk&detectOrientation =true Content-Type: application/json Host: api.projectoxford.ai Content-Length: 95 Ocp-Apim-Subscription-Key: •••••••••••••••••••••••••••••••• { "Url": "exampleurl.com"} As well as the URL request and need help on...


c# - Http Post data from Python to net core app

I am trying to send a file from a Python script to my .net core webserver. In Python I am doing this using the requests library, and my code looks like so. filePath = "run-1.csv" with open(filePath, "rb") as postFile: file_dict = {filePath: postFile} response = requests.post(server_path + "/batchUpload/create", files=fi...


HTTP GET In Python

I have a bash script that downloads a lot of files from a URL and saves them to my Computer like: curl 'http://website.com/shop.php?store_id=[66-900]&page=[7-444]&PHPSESSID=phpsessid' -O (and a bunch of headers set, the typical request you get when you copy a request as curl in firefox) Tried to rewrite the script in python but turns out it is very hard (complete newbie) like:...


python - What's the best Django search app?


How can I use a DLL file from Python?

What is the easiest way to use a DLL file from within Python? Specifically, how can this be done without writing any additional wrapper C++ code to expose the functionality to Python? Native Python functionality is strongly preferred over using a third-party library.


python - PubSub lib for c#

Is there a c# library which provides similar functionality to the Python PubSub library? I think it's kind of an Observer Pattern which allows me to subscribe for messages of a given topic instead of using events.


python - What is the best way to copy a list?

This question already has answers here:


python - Possible Google Riddle?

My friend was given this free google website optimizer tshirt and came to me to try and figure out what the front logo meant. t-shirt So, I have a couple of guesses as to what it means, but I was just wondering if there is something more. My first guess is that eac...


How do you check whether a python method is bound or not?

Given a reference to a method, is there a way to check whether the method is bound to an object or not? Can you also access the instance that it's bound to?


ssh - How to scp in Python?

What's the most pythonic way to scp a file in Python? The only route I'm aware of is os.system('scp "%s" "%s:%s"' % (localfile, remotehost, remotefile) ) which is a hack, and which doesn't work outside Linux-like systems, and which needs help from the Pexpect module to avoid password prompts unless you already have passwordless SSH set up to the remote host. I'm aware of Twisted'...


python - How do I create a new signal in pygtk

I've created a python object, but I want to send signals on it. I made it inherit from gobject.GObject, but there doesn't seem to be any way to create a new signal on my object.


python - What do I need to import to gain access to my models?

I'd like to run a script to populate my database. I'd like to access it through the Django database API. The only problem is that I don't know what I would need to import to gain access to this. How can this be achieved?


python - How do I edit and delete data in Django?

I am using django 1.0 and I have created my models using the example in the Django book. I am able to perform the basic function of adding data; now I need a way of retrieving that data, loading it into a form (change_form?! or something), EDIT it and save it back to the DB. Secondly how do I DELETE the data that's in the DB? i.e. search, select and then delete! Please show me an example of the code ...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top