Reputation: 525
I trying to make a POST call using urllib (python 3.5), but can't figure it out. There are plenty examples on how to make either POST call without auth or call with auth, but GET... I'm struggling to put 2 and 2 together! Could someone please help me with a code?
Upvotes: 1
Views: 2000
Reputation: 1214
You can try:
import urllib.request
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='name',
uri='url',
user='user',
passwd='pass')
opener = urllib.request.build_opener(auth_handler)
urllib.request.install_opener(opener)
req = urllib.request.Request(url=some_url, data=data, method='POST')
urllib.request.urlopen(req)
Upvotes: 3