I am completely new to Python. I need to post an authentication request to a website using header and body details. I have posted the code below that I have so far. When I run it, I get syntax error on this line:
req.add_header('API-KEY': 'my_api_key', 'ACCOUNT-ID': 'my_account_id', 'Content-Type': 'application/json; charset=UTF-8', 'VERSION': '2')
Can you please review and let me know where I've gone wrong?
import urllib.request
import json
body = {'identifier': 'my_id', 'password': 'my_encrypted_pwd', 'encryptedPassword': true}
url = 'https://mywebsite.com/gateway/deal/session'
req = urllib.request.Request(url)
req.add_header('API-KEY': 'my_api_key', 'ACCOUNT-ID': 'my_account_id', 'Content-Type': 'application/json; charset=UTF-8', 'VERSION': '2')
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('UTF-8')
req.add_header('Content-Length', len(jsondataasbytes))
print (jsondataasbytes)
response = urllib.request.urlopen(req, jsondataasbytes)