top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Posting data using MultipartPostHandler in Python

+1 vote
210 views

I want to use http post to upload data to a webserver but I want to pass multiple arguments within the post i.e. I know that you can load one item (data)in there like this:

 data = {"data":open(filename,"rb")}
 response = opener.open(url, data, timeout=TIMEOUT)

but now I want multiple so I tried this:

 multipart = ({"data":data}, {"fname":fname}, {"f":f})
 response = opener.open(url, multipart, timeout=TIMEOUT)

but I get an error saying "'tuple' object has no attribute 'items'"... how do I do this correctly?

posted Aug 15, 2013 by Bob Wise

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You're no longer providing a dictionary, but a tuple of dictionaries. What you want to do is use a single dictionary:

multipart = {"data":data, "fname":fname, "f":f}

That should achieve what you want.

answer Aug 16, 2013 by Kumar Mitrasen
Similar Questions
0 votes

Please give me some idea about how we can query the DNS
How you have divided the passive dns functioning into two parts as recursor and resolver.
Can you please give some idea about how they function, and when they are employed after the query is submitted to the pdns
How the data packet will be analyzed for ddos attack.

0 votes

I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file.

Presently I am using this:

with open('index.txt','w') as f:
 f.write("".join(data))
 f.close()

where data is a list of strings which I want to dump into the index.txt file

0 votes

I have a Ubuntu server running NGINX that logs data for me. I want to write a python script that reads my customized logs and after a little rearrangement save the new data into my DB (postgresql).

The process should run about every 5 minutes and i'm expecting large chunks of data on several 5 minute windows..

My plan for achieving this is to install python on the server, write a script and add it to cron.

My question is what the simplest way to do this? should I use any python frameworks?
For my python app I'm using Django, but on this server I just need to read a file, do some manipulation and save to DB.

...