Page 1 of 1

Header support in urllib or requests

Posted: Thu Jun 09, 2016 2:38 pm
by hansamann
Looking at the urllib.urequest code, it seems there is no header support at all. That's the reason why my current request is failing. Is there a chance to get header support implemented soon?

import urllib.urequest
endpoint = 'https://api.yaas.io/hybris/oauth2/b1/token'
urlencoded = 'grant_type=client_credentials&scope=&client_id=xxx&client_secret=xxx'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = urllib.urequest.urlopen(endpoint, data=urlencoded, method="POST")
json = response.read()

//FAILS - no Content-Type specified and the API does not seem to support it right now.

Re: Header support in urllib or requests

Posted: Thu Jun 09, 2016 3:01 pm
by deshipu
You can use urequests instead, which has support for headers.

Re: Header support in urllib or requests

Posted: Thu Jun 09, 2016 3:03 pm
by pfalcon
Unfortunately, it doesn't. Let's see if this gets reported on github, so maintainers didn't forget to fix it ;-).

Re: Header support in urllib or requests

Posted: Thu Jun 09, 2016 3:04 pm
by deshipu
Also, it seems that urllib.urequest does support headers:

Code: Select all

response = urllib.urequest.urlopen(endpoint, data=urlencoded, headers=headers, method="POST")

Re: Header support in urllib or requests

Posted: Thu Jun 09, 2016 10:47 pm
by pfalcon
Arbitrary headers support has been added to urequests. Please test it and report results.