Reputation: 461
I am going to get my data but I am getting errors as indicated on the title. I am requesting a post with no data but with parameters in url
here is my code
def post_and_get_id(self):
url = 'https://heremyurl_post'
data = {
'last_name': self.last_name,
'first_name': self.first_name,
'is_admin': self.is_admin,
'is_active': True
}
headers = {'Authorization': 'Bearer %s' % self.authentication(), 'Content-type': 'application/json'}
payload = json.dumps(data)
request = requests.post(url, data=payload, headers=headers)
response = request.json()
return response['id']
def get_client(self):
id = self.post_and_get_id()
url = f'https://my_url_get_data?id={id}'
headers = {'Authorization': 'Bearer %s' % self.authentication(), 'Content-Type': 'application/json'}
request = requests.post(url, headers=headers)
print(request.content)
return request.json()
Traceback
Traceback (most recent call last):
File "main.py", line 70, in <module>
print(object.get_client())
File "main.py", line 66, in get_client
return request.json()
File "/venv/lib/python3.8/site-packages/requests/models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
here are my steps first I am posting a data to URL to get id and with that id, I can get data by post requests. Unfortunately, it is not working self.authentication()
is a method for token. Everything is working except get_client()
method . Please can anyone help me? Any help would be appreciated!
PS
With that ID I posted in the postman it worked but in my code not (
Upvotes: 0
Views: 729
Reputation: 11505
Well, within first function you've to return the Auth token which you used.
You don't need to recall it from second function as it's will generate a new one.
Upvotes: 1