Advertisement
Ifrail

json response

Nov 19th, 2020
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. import requests
  2.  
  3. url = 'http://example.com'
  4. data = {"request":"login", "data":{"login":"user","password":"pwd"}}
  5.  
  6. response = requests.post(url, data=data)
  7.  
  8. #headers = {"Content-Type":"application/json"}
  9. if response.ok and 'application/json' in response.headers.get('content-type'):
  10.     print(response.json().keys())
  11.  
  12. #Пример с работающим ответом в формате json()
  13. import requests
  14.  
  15. response = requests.get('https://api.github.com/some/endpoint')
  16. if 'application/json' in response.headers.get('content-type'):
  17.     print(response.json().keys())
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement