[PYTHON] requests

#pip intall requests
import requests

payload = {'key1': 'value1', 'key2': 'value2'}

#If no result is returned from the server after 1 second, an error will occur.
r = requests.get('http://httpbin.org/get', params=payload, timeout=1)
#r = requests.post('http://httpbin.org/post', data=payload)
#r = requests.put('http://httpbin.org/put', data=payload)
#r = requests.delete('http://httpbin.org/delete', data=payload)

print(r.status_code)
print(r.text)
print(r.json())

output:

200
{
  "args": {
    "key1": "value1", 
    "key2": "value2"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.22.0", 
    "X-Amzn-Trace-Id": "Root=1-5e682022-f3f210e8d7f8b036364f33b8"
  }, 
  "origin": "118.158.151.210", 
  "url": "http://httpbin.org/get?key1=value1&key2=value2"
}

{'args': {'key1': 'value1', 'key2': 'value2'}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.22.0', 'X-Amzn-Trace-Id': 'Root=1-5e682022-f3f210e8d7f8b036364f33b8'}, 'origin': '118.158.151.210', 'url': 'http://httpbin.org/get?key1=value1&key2=value2'}

Recommended Posts

requests
Creating Pull Requests
Download images using requests
Use ujson in requests
Retry with python requests
Python Requests status code