req = urllib.request.Request(url)
if kwargs:
    req.add_data(urllib.parse.urlencode(kwargs))
auth = 'Basic ' + base64.urlsafe_b64encode('%s:%s' % (USER, PASS))
req.add_header('Authorization', auth)
return urllib.request.urlopen(req)
Using POST and urllib2 to access web API