maybe someone can help me with this. I'm trying to get a data from a website using Python 2.7, using HTTP Basic Authentication. The only instructions the website provides is this:
In order for your web service client to authenticate using basic authentication, the first HTTPS request must include the "Authorization" header specifying the account credentials to authenticate with. The header for a such a request would look like this:
GET /polcs/trade.xml HTTP/1.0 Host: secure.pol.com Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
I tried few things but neither of them works, for example:
import urllib2
import base64
b = base64.encodestring('USERNAME:PASSWORD').replace('\n', '')
conf = {'headers': {'GET': '/polcs/trade.xml HTTP/1.0', 'Authorization': 'Basic ' + b},
'url': 'secure.pol.com'}
datas = None
request = urllib2.Request(conf['url'], datas, conf['headers'])
result = urllib2.urlopen(request)
This one gives me HTTP Error 403:
url = 'https://secure.pol.com/polcs/data.xml'
request = urllib2.Request(url)
b = base64.encodestring('USERNAME:PASSWORD').replace('\n', '')
request.add_header("Authorization", "Basic " + b)
result = urllib2.urlopen(request)
Can someone please tell me where do I make a mistake trying to get that data? Thank you!