Home > OS >  GET request with files argument in requests library Python
GET request with files argument in requests library Python

Time:10-08

I find this code and I really don't understand it, how is it possible to send data (not query) with GET request

response = requests.get(
            check_all_info_url_2, files=multipart_form_data, timeout=30)

and what is files= argument in the get request.

CodePudding user response:

Since requests.get is just a wrapper function this will just call requests.request. Unless requests.session implementes any checking, it will happily send off a GET request with multipart data in it.

Is this valid? Not to my knowledge, although I'm willing to be proven wrong. No api I have ever written would accept file upload on a GET request. But not every server will even check the method, so perhaps this code is interacting with a badly written server which doesn't reject for wrong method, or perhap's it's even interacting with a worse server which expects file upload with GET. There are lots of broken servers out there ;)

In any case, the reason this works with requests is that it just passes keyword arguments through to the underlying session without performing any kind of validation.

  • Related