Skip to content

Instantly share code, notes, and snippets.

@vik-y
Created January 15, 2015 18:33
Show Gist options
  • Save vik-y/e237eb9cb9633c8b28a3 to your computer and use it in GitHub Desktop.
Save vik-y/e237eb9cb9633c8b28a3 to your computer and use it in GitHub Desktop.
Python Web Requests
import requests
#We often have to automate some task, using requests library can be pretty easy as we
#Dont have to bother about the headers which we send along with our call and lets us do things fast.
'''
Functions to send Simple get and post request along with payload
payload is a dictionary
cookie is also a dictionary of key value pair
'''
def get_request(payload, url, cookie):
r = requests.get(url, params=payload, cookies = cookie)
return r; # r.text gives exact text/html/json response which came from the server
def post_request(payload, url, cookie):
r = requests.post(url, data=payload, cookies = cookie)
return r; # r.text gives exact text/html/json response which came from the server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment