shopify - Python Requests Invalid URL Label error -
i'm trying access shopify's api uses url format of - https://apikey:password@hostname/admin/resource.xml
e.g.http://7ea7a2ff231f9f7:95c5e8091839609c864@iliketurtles.myshopify.com/admin/orders.xml
doing $curl api_url downloads correct xml when
import requests api_url = 'http://7ea7a2ff231f9f7d:95c5e8091839609c864@iliketurtles.myshopify.com/admin/orders.xml' r = requests.get(api_url) # invalid url label error any idea why i'm getting this? curl / opening link directly in browser working fine. because length of url long?
thanks!
the error ('url has invalid label.') bug in requests library: applies idna encoding (for internationalized domain names) on hostname userinfo attached, source:
netloc = netloc.encode('idna').decode('utf-8') that might raise 'label empty or long' error long username:password. can try report on requests' issue tracker.
a:b@example.com form deprecated otherwise requests.get('https://a:b@example.com') should equivalent requests.get('https://example.com', auth=('a', 'b')) if characters in username:password [-a-za-z0-9._~!$&'()*+,;=] set.
curl , requests differ there percent-encoded characters in userinfo e.g., https://a:%c3%80@example.com leads curl generating following http header:
authorization: basic ytrdga== but requests produces:
authorization: basic ytolqzmloda= i.e.:
>>> import base64 >>> base64.b64decode('ytrdga==') 'a:\xc3\x80' >>> print _ a:À >>> base64.b64decode('ytolqzmloda=') 'a:%c3%80'
Comments
Post a Comment