Hitch-22
0
Q:

get request python

import requests

url = 'https://www.w3schools.com/python/demopage.php'
myobj = {'somekey': 'somevalue'}

x = requests.post(url, data = myobj)

print(x.text)
18
import requests

url = 'https://www.w3schools.com/python/demopage.php'
myobj = {'somekey': 'somevalue'}
x = requests.post(url, data = myobj)

print(x.text)
 
4

    import requests

x = requests.get('https://w3schools.com/python/demopage.htm')

print(x.text)
 
3
>>> import requests
>>> r = requests.post('http://httpbin.org/post', json={"key": "value"})
>>> r.status_code
200
>>> r.json()
{'args': {},
 'data': '{"key": "value"}',
 'files': {},
 'form': {},
 'headers': {'Accept': '*/*',
             'Accept-Encoding': 'gzip, deflate',
             'Connection': 'close',
             'Content-Length': '16',
             'Content-Type': 'application/json',
             'Host': 'httpbin.org',
             'User-Agent': 'python-requests/2.4.3 CPython/3.4.0',
             'X-Request-Id': 'xx-xx-xx'},
 'json': {'key': 'value'},
 'origin': 'x.x.x.x',
 'url': 'http://httpbin.org/post'}
2
# pip install requests
import requests
req = requests.get('<url here>', 'html.parser')
print(req.text)
2
import requests

r = requests.get('https://api.github.com', auth=('user', 'pass'))

print r.status_code
print r.headers['content-type']
2
import socket

target_host = "www.google.com" 
target_port = 80

# create a socket object 
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
 
# connect the client 
client.connect((target_host,target_port))  

# receive some data 
response = client.recv(4096)
print(f'Source Code: {response}')
http_response = repr(response)
1
import requests

x = requests.get('https://w3schools.com')
print(x.status_code)
-1
# pip install requests
import requests
req = requests.post('<url here>', 'html.parser')
print(req.text)
1
Raise an exception if a request is unsuccessful

import requests
url = "http://mock.kite.com/status/404"
r = requests.get(url)
try: 
    r.raise_for_status()
except requests.exceptions.HTTPError as e: 
    print e
OUTPUT
404 Client Error: NOT FOUND
-1
# importing the requests library 
import requests 
  
# api-endpoint 
URL = "http://maps.googleapis.com/maps/api/geocode/json"
  
# location given here 
location = "delhi technological university"
  
# defining a params dict for the parameters to be sent to the API 
PARAMS = {'address':location} 
  
# sending get request and saving the response as response object 
r = requests.get(url = URL, params = PARAMS) 
  
# extracting data in json format 
data = r.json()
-1

New to Communities?

Join the community