Need some help here. I am trying to send a JWT token with header in my request. When i directly copy paste the token in the request (line 6) its working fine. Where as when i concatenate as string and send (line 3 & 5) it throwing error. But when print the token its having the correct token value.THe error i have pasted below after the code
response = requests.post("some URL")
token = response.text
header_content = "{'Authorization': 'Bearer "+token+"'}"
print(header_content)
response = requests.get(url, headers=header_content)
#response = requests.get(url, headers = {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6ImhjbF9yZXBvcnRpbmcuc2VydmljZWFjY291bnRAc2x1LnRlYW1keW5hbWl4LmNvbSIsInRkeF9lbnRpdHkiOiIyIiwidGR4X3BhcnRpdGlvbiI6IjcwIiwiaXNzIjoiVEQiLCJhdWQiOiJodHRwczovL3d3dy50ZWFtZHluYW1peC5jb20vIiwiZXhwIjoxNjIyOTgyNzg5LCJuYmYiOjE2MjI4OTYzODl9.82FuBtybRBk3Ot-whKYEXw2yFeNXBp566MubEA9G-BE'})
the error i am seeing is
Traceback (most recent call last):
File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\Rest_Testing.py", line 24, in <module>
response = requests.get(url, headers=header_content)
File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\venv\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\venv\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\venv\lib\site-packages\requests\sessions.py", line 528, in request
prep = self.prepare_request(req)
File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\venv\lib\site-packages\requests\sessions.py", line 456, in prepare_request
p.prepare(
File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\venv\lib\site-packages\requests\models.py", line 317, in prepare
self.prepare_headers(headers)
File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\venv\lib\site-packages\requests\models.py", line 449, in prepare_headers
for header in headers.items():
AttributeError: 'str' object has no attribute 'items'