Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python requests

>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
u'{"type":"User"...'
>>> r.json()
{u'private_gists': 419, u'total_private_repos': 77, ...}
Comment

requests

>>> import requests
>>> r = requests.get('https://httpbin.org/basic-auth/user/pass', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
'{"authenticated": true, ...'
>>> r.json()
{'authenticated': True, ...}
Comment

python requests

# requires pip install requests
import requests

# webpage url to sent request to
url = 'https://www.google.com'

# send get requests
x = requests.get(url=url)

# print status code of request
print(x.status_code)

# print webpage source code text
print(x.text)

# print webpage as json
print(x.json)

# print webpage headers
print(x.headers)

# send a get request and timeout if it takes longer than 2.5 seconds
x = requests.get(url=url, timeout=2.5)

# demonstrate how to use the 'params' parameter: query string
x = requests.get(url=url, params={"model": "Mustang"})


####################

# require pip install requests
import requests

url = 'https://www.google.com'
form_data = {'username': 'john', 'password': "pwd"}

# send post request
x = requests.post(url=url, json=form_data)

# send post request and timeout if it takes longer than 3 seconds
x = requests.post(url=url, json=form_data, timeout=3)

# use the 'auth' parameter to send requests with HTTP Basic Auth:
x = requests.post(url, data=from_data, auth=('user', 'pass'))

print(x.text)
print(x.headers)
print(x.status_code)
Comment

python requests

Url = "https://"

r = requests.get( Url )

data = r.json()
Comment

PREVIOUS NEXT
Code Example
Python :: breadth first search graph python 
Python :: extract one column from dataframe python 
Python :: django pandas queryset 
Python :: python create directory if non existent 
Python :: how to run a python script 
Python :: dummy variables pandas 
Python :: how to get confusion matrix in python 
Python :: python search first occurrence in string 
Python :: suppress python 
Python :: round off float to 2 decimal places in python 
Python :: how to code python 
Python :: how to get input with python 
Python :: Play Audio File In Background Python 
Python :: python sort array by value 
Python :: pandas unique values to list 
Python :: fasttext python 
Python :: python get value from dictionary 
Python :: try except json decode error 
Python :: how to run same function on multiple threads in pyhton 
Python :: python check if list contains 
Python :: correlation with specific columns 
Python :: python pillow cut image in half 
Python :: replace nan with 0 pandas 
Python :: randomly shuffle pandas dataframe 
Python :: match python 3.10 
Python :: iterate over classes in module python 
Python :: django production 
Python :: seaborn pink green color palette python 
Python :: how to unlist a list in python 
Python :: not null constraint failed django 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =