python - Set name header of multipart-encoded file POST -


I'm trying to use a file to upload, but I'm getting the error from the template server: < / P>

The request sent by the client was syntactically incorrect. After reading

I have managed to print the request I am making and when comparing the request made in this browser, I have seen that the request payload is not a coalition, so I'm guessing that this is my problem.

Request for multiparty posting- Encoded file shows that you can explicitly override the filename, content-type and header:

  & gt; ; & Gt; & Gt; Url = 'http://httpbin.org/post' & gt; & Gt; & Gt; Files: ('report.xls', ('report.xls', 'rb') open, 'application / vnd.ms-excel', {'expires': '0'})}   

It works fine but as mentioned above, I also need to set the name and filename and I content-type < / Code>.

Excavation around the GitHub repo seems to allow me to specify the _encode_files method in names :

  RF = RequestField (name = K, data = fp.read (), file name = FN, header = FH) but I can not do this to work and in my application With the above example, I have the file name specified in the context of the file name:  
  files = {'file': (filename, open (  

m What's missing from here?

The name will be the key in your files To set the name field in the desired area, simply change that key:

 > <>> Import request >> & gt; & gt; ('Foo.txt', 'foo \ ncontents \ n', 'text / plain')}> gt; & gt; REQ = request. Request ('post', 'foo.txt', 'foo.txt', 'foo.txt' 'Http://httpbin.org/post', files = files) .prepare ()> gt; & Gt; & Gt; Print req.body - 49773910d9514216894b697cb70e9f21 Content-configuration: form-data; Name = "foobar"; File name = "foo.txt" content-type: text / plain foo content - 49773910d9514216894b697cb70e9f21--   

note that name = "foobar" -text < Code> content-dispute header.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -