I have the code below in a AWS lambda function which makes a REST post request. The code worked in 2.7, but is throwing an error in 3.7.
The error is in the header portion of the request. But I'm not clear on how to fix it.
The code snippet is listed below:
DOMAIN = 'xxx-yyy.com'
TOKEN = 'xdfbvgsded5e9fb99a'
JOB = 1
build_url = f'https://{DOMAIN}/api/2.0/jobs/run-now'
response = requests.post(build_url,headers={'Authorization': b"Basic " + base64.standard_b64encode(b"token:" + TOKEN)}, json={"job_id": JOB})
# response = requests.get("http://www.google.com")
if response.status_code == 200:
print("Request Submitted")
else:
print("Error launching cluster")```
Error message
```{
"errorMessage": "can't concat str to bytes",
"errorType": "TypeError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 11, in lambda_handler\n headers = {'Authorization': b\"Basic \" + base64.standard_b64encode(b\"token:\" + TOKEN)}\n"```
]
} ```
base64.standard_b64encode(b"token:" + TOKEN)}? Seems like it could be because its bytes. The header values should be a string and not bytes