Answers for "request to url python"

2

urllib.request headers

try:
    from urllib.request import Request, urlopen  # Python 3
except ImportError:
    from urllib2 import Request, urlopen  # Python 2

req = Request('http://api.company.com/items/details?country=US&language=en')
req.add_header('apikey', 'xxx')
content = urlopen(req).read()

print(content)
Posted by: Guest on April-04-2020
0

urllib urlretrieve python 3

#In Python 3.x, the urlretrieve function is located in the urllib.request module:
from urllib.request import urlretrieve
Posted by: Guest on June-25-2020
0

python get response from url

import requests
r = requests.get("https://google.com")
print(r.status_code)
#100- 199 Informational
#200-299 Succes
#300-399 Redirection
#400-499 CLIENT ERROR 
#500-599 SERVER ERROR
Posted by: Guest on October-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language