You can use the requests library, it simplifies things a lot in comparison to taking the urllib2 approach. First install it from pip:
pip install requestrequests More on installing requests.
Then setup the put request:
import requests import json url = 'https://api.github.com/some/endpoint' payload = {'some': 'data'} # Create your header as required headers = {"content-type": "application/json", "Authorization": "<auth-key>" } r = requests.put(url, data=json.dumps(payload), headers=headers) See the quickstart for requests library. I think this is a lot simpler than urllib2 but does require this additional package to be installed and imported.