Skip to content

Instantly share code, notes, and snippets.

Last active January 25, 2024 12:23
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joshisumit/35e9ee3e68e5210af331 to your computer and use it in GitHub Desktop.
Create GIST from your python code with python requests module and OAuth token.
HTTP Reuests has following parameters:
1)Request URL
2)Header Fields
4)Request body
#!/usr/bin/env python
import requests
import json
#form a request URL
print "Request URL: %s"%url
#print headers,parameters,payload
headers={'Authorization':'token %s'%API_TOKEN}
payload={"description":"GIST created by python code","public":True,"files":{"python request module":{"content":"Python requests has 3 parameters: 1)Request URL\n 2)Header Fields\n 3)Parameter \n4)Request body"}}}
#make a requests,headers=headers,params=params,data=json.dumps(payload))
#print response --> JSON
print res.status_code
print res.url
print res.text
# Print created GIST's details
for gist in range(len(j)):
print "Gist URL : %s"%(j['url'])
print "GIST ID: %s"%(j['id'])
Copy link

RAMSlog commented Mar 19, 2019

I got a 401 response. what should I do?
it did well on the first try, but it doesn't work after

Copy link


Copy link

I keep getting "KeyError: 'id'", any solutions to that?

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment