Python - Requests Library

Requests is an elegant and simple HTTP library for Python built for human beings.

Installation

Using pipenv

pipenv install requests

Using Source Code

$ git clone git://github.com/requests/requests.git

$ curl -OL https://github.com/requests/requests/tarball/master

$ cd requests
$ pip install .

Make a request


In [1]:
import requests

In [9]:
# get request
r = requests.get('https://api.github.com/events')
r.url


Out[9]:
'https://api.github.com/events'

In [11]:
# post request
r = requests.post('http://httpbin.org/post', data={'name':'john'})
r.status_code


Out[11]:
200

In [14]:
# put request
r = requests.put('http://httpbin.org/put',data={'name':'john doe'})
r.status_code


Out[14]:
200

In [15]:
# delete request
r = requests.delete('http://httpbin.org/delete')
r.status_code


Out[15]:
200

In [17]:
# header request
r = requests.head('http://httpbin.org/get')
r.content


Out[17]:
b''

Passing Parameters in Urls


In [19]:
# passing params
payload={'name':'john','age':12}
r = requests.get('http://httpbin.org/get',params=payload)
r.url


Out[19]:
'http://httpbin.org/get?name=john&age=12'

Whenever a call is made to requests.get() first a Request object is constructed and a response object is generated once Requests gets a response back from the server. The Response object contains all of the information returned by the server and also contains the Request object you created originally.


In [75]:
r = requests.get('http://en.wikipedia.org/wiki/Monty_Python')

In [76]:
# access the headers the server sent back to us
r.headers


Out[76]:
{'Date': 'Thu, 16 Nov 2017 11:18:59 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Content-Length': '73764', 'Connection': 'keep-alive', 'Server': 'mw1263.eqiad.wmnet', 'Vary': 'Accept-Encoding,Cookie,Authorization', 'X-Powered-By': 'HHVM/3.18.6-dev', 'Content-Encoding': 'gzip', 'P3P': 'CP="This is not a P3P policy! See https://en.wikipedia.org/wiki/Special:CentralAutoLogin/P3P for more info."', 'X-Content-Type-Options': 'nosniff', 'Content-language': 'en', 'X-UA-Compatible': 'IE=Edge', 'Link': '</static/images/project-logos/enwiki.png>;rel=preload;as=image;media=not all and (min-resolution: 1.5dppx),</static/images/project-logos/enwiki-1.5x.png>;rel=preload;as=image;media=(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),</static/images/project-logos/enwiki-2x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)', 'Last-Modified': 'Tue, 07 Nov 2017 16:47:43 GMT', 'Backend-Timing': 'D=117219 t=1510411294734865', 'X-Varnish': '130681237 511233313, 298196649 236933887, 93421014 1570072, 850583859 824231', 'Via': '1.1 varnish-v4, 1.1 varnish-v4, 1.1 varnish-v4, 1.1 varnish-v4', 'Age': '242752', 'X-Cache': 'cp1068 hit/15, cp2023 hit/9, cp4027 hit/9, cp4028 hit/82', 'X-Cache-Status': 'hit-front', 'Strict-Transport-Security': 'max-age=106384710; includeSubDomains; preload', 'X-Analytics': 'ns=0;page_id=18942;WMF-Last-Access=16-Nov-2017;WMF-Last-Access-Global=16-Nov-2017;https=1', 'X-Client-IP': '175.136.245.133', 'Cache-Control': 'private, s-maxage=0, max-age=0, must-revalidate', 'Set-Cookie': 'GeoIP=MY:14:Kuala_Lumpur:3.12:101.68:v4; Path=/; secure; Domain=.wikipedia.org', 'Accept-Ranges': 'bytes'}

In [77]:
# headers we sent to the server
r.request.headers


Out[77]:
{'User-Agent': 'python-requests/2.14.2', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Cookie': 'WMF-Last-Access=16-Nov-2017; WMF-Last-Access-Global=16-Nov-2017'}

Prepared Requests

Whenever we receive a Response object from an API call or a Session call, the request attribute is actually the PreparedRequest that was used. In some cases you may wish to do some extra work to the body or headers before sending a request.


In [81]:
s = requests.Session()

req = requests.request('POST',url,data=data,headers=headers)
prepped = req.prepare()

# do something with prepped body
prepped.body = 'No I want exactly this as the body'

# do something with prepped.headers
del prepped.headers['Content-Type']

resp = s.send(prepped,stream=stream,verify=verify,proxies=proxies,cert=cert,timeout=timeout)

print(resp.status_code)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-81-71edd167d011> in <module>()
      1 s = requests.Session()
      2 
----> 3 req = requests.request('POST',url,data=data,headers=headers)
      4 prepped = req.prepare()
      5 

NameError: name 'data' is not defined

However the above code will lose some of the advantages of having a Requests Session object. In particular, Session-level state such as cookies will not get applied to your request. To get a PreparedRequest with that state applied, replace the call to Request.prepare() with a call to Session.prepare_request() like this:


In [ ]:
s = requests.Session()

req = requests.request('GET',url,data=data,headers=headers)
prepped = s.prepare_request(req)

# do something with prepped body
prepped.body = 'No I want exactly this as the body'

# do something with prepped.headers
del prepped.headers['Keep-Deatd'] = 'parrot'

resp = s.send(prepped,stream=stream,verify=verify,proxies=proxies,cert=cert,timeout=timeout)

print(resp.status_code)

When you are using the prepared request flow, keep in mind that it does not take into account the environment. This can cause problems if you are using environment variables to change the behavior of requests. For example Self-signed SSL certificates specified in REQUESTS_CA_BUNDLE will not taken into account. You can get around this behavior by explicitly merging the environment settings into the session:


In [ ]:
s = requests.Session()

req = requests.request('POST',url,data=data,headers=headers)
prepped = s.prepare_request(req)

# do something with prepped body
prepped.body = 'No I want exactly this as the body'

# Merger environment settings into session
settings = s.merge_environment_settings(prepped.url,None,None,None,None)

resp = s.send(prepped, **settings)

print(resp.status_code)

Response Content

Text Response Content


In [20]:
# get request
r = requests.get('https://api.github.com/events')
print(r.text)


[{"id":"6862547960","type":"CreateEvent","actor":{"id":33421045,"login":"enminqui","display_login":"enminqui","gravatar_id":"","url":"https://api.github.com/users/enminqui","avatar_url":"https://avatars.githubusercontent.com/u/33421045?"},"repo":{"id":110930710,"name":"enminqui/Hello-world","url":"https://api.github.com/repos/enminqui/Hello-world"},"payload":{"ref":null,"ref_type":"repository","master_branch":"master","description":"My first repositori","pusher_type":"user"},"public":true,"created_at":"2017-11-16T06:09:36Z"},{"id":"6862547951","type":"PushEvent","actor":{"id":33706433,"login":"shrocky2","display_login":"shrocky2","gravatar_id":"","url":"https://api.github.com/users/shrocky2","avatar_url":"https://avatars.githubusercontent.com/u/33706433?"},"repo":{"id":110907964,"name":"shrocky2/Alexa_TiVo","url":"https://api.github.com/repos/shrocky2/Alexa_TiVo"},"payload":{"push_id":2128121542,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"59d6349c47ba597179315a7c50e2305dec7d2d21","before":"142bd4f6d48c3b34a6e97f100006db50846d3d1f","commits":[{"sha":"59d6349c47ba597179315a7c50e2305dec7d2d21","author":{"email":"33706433+shrocky2@users.noreply.github.com","name":"shrocky2"},"message":"Update TiVo_List1.py","distinct":true,"url":"https://api.github.com/repos/shrocky2/Alexa_TiVo/commits/59d6349c47ba597179315a7c50e2305dec7d2d21"}]},"public":true,"created_at":"2017-11-16T06:09:36Z"},{"id":"6862547946","type":"PushEvent","actor":{"id":5696422,"login":"samlanh","display_login":"samlanh","gravatar_id":"","url":"https://api.github.com/users/samlanh","avatar_url":"https://avatars.githubusercontent.com/u/5696422?"},"repo":{"id":109637202,"name":"samlanh/saledrinksystem","url":"https://api.github.com/repos/samlanh/saledrinksystem"},"payload":{"push_id":2128121539,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"e6cf7bfc89a1fac3ce3c171833f859000d0af2e9","before":"01d9d2076a6dae586f4d0a46717f4f2b229449e7","commits":[{"sha":"e6cf7bfc89a1fac3ce3c171833f859000d0af2e9","author":{"email":"mok_channy@yahoo.com","name":"samlanh"},"message":"commit to server","distinct":true,"url":"https://api.github.com/repos/samlanh/saledrinksystem/commits/e6cf7bfc89a1fac3ce3c171833f859000d0af2e9"}]},"public":true,"created_at":"2017-11-16T06:09:36Z"},{"id":"6862547939","type":"PushEvent","actor":{"id":22697900,"login":"daoyi7","display_login":"daoyi7","gravatar_id":"","url":"https://api.github.com/users/daoyi7","avatar_url":"https://avatars.githubusercontent.com/u/22697900?"},"repo":{"id":110658002,"name":"daoyi7/r-2ex","url":"https://api.github.com/repos/daoyi7/r-2ex"},"payload":{"push_id":2128121537,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"44e72ab0d6feb476eaea1b54cd2d9ef234b52bd7","before":"7e2eb7914917a07bc0aebfe3a3c48d56768145ad","commits":[{"sha":"44e72ab0d6feb476eaea1b54cd2d9ef234b52bd7","author":{"email":"kawhichina@gmail.com","name":"daoyi7"},"message":"update Component -> detail.js","distinct":true,"url":"https://api.github.com/repos/daoyi7/r-2ex/commits/44e72ab0d6feb476eaea1b54cd2d9ef234b52bd7"}]},"public":true,"created_at":"2017-11-16T06:09:36Z"},{"id":"6862547936","type":"WatchEvent","actor":{"id":1634635,"login":"apolikamixitos","display_login":"apolikamixitos","gravatar_id":"","url":"https://api.github.com/users/apolikamixitos","avatar_url":"https://avatars.githubusercontent.com/u/1634635?"},"repo":{"id":12357974,"name":"pimutils/khal","url":"https://api.github.com/repos/pimutils/khal"},"payload":{"action":"started"},"public":true,"created_at":"2017-11-16T06:09:36Z","org":{"id":17852924,"login":"pimutils","gravatar_id":"","url":"https://api.github.com/orgs/pimutils","avatar_url":"https://avatars.githubusercontent.com/u/17852924?"}},{"id":"6862547916","type":"PushEvent","actor":{"id":9599,"login":"simonw","display_login":"simonw","gravatar_id":"","url":"https://api.github.com/users/simonw","avatar_url":"https://avatars.githubusercontent.com/u/9599?"},"repo":{"id":102992755,"name":"simonw/disaster-data","url":"https://api.github.com/repos/simonw/disaster-data"},"payload":{"push_id":2128121522,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"40c218146edf1350f78b2114f170c9556a433b59","before":"a565e44fc763393a20397b3ec236e450082b8d35","commits":[{"sha":"40c218146edf1350f78b2114f170c9556a433b59","author":{"email":"irma-scraper@example.com","name":"irma-scraper"},"message":"chp-incidents: 6 incidents added, 1 incident removed, 112 incidents changed\n\n6 new incidents:\n  CHP Incident 171115GG03421\n    https://www.google.com/maps/search/-122.125001,37.892862\n    Nov 15 2017 10:07PM  1179-Trfc Collision-1141 Enrt  Sr24 E / Oak Hill Rd Ofr \n  Nov 15 2017 10:08PM [4] [1] SOLO VEH TC , FACING WW IN # 3 LANE  Information courtesy of \n  Last updated: 11/15/2017 10:09pm \n\n  CHP Incident 171115GG03418\n    https://www.google.com/maps/search/-121.887158,37.643095\n    Nov 15 2017 10:07PM  1183-Trfc Collision-Unkn Inj  I680 N / Sunol Blvd Onr \n  Nov 15 2017 10:08PM [4]  UNKN  IF DEER INRDWY Nov 15 2017 10:08PM [3]   PORS IN CD  Nov 15 2017 10:07PM [2]    BLU PORS CAY VS  DEER  Information courtesy of \n  Last updated: 11/15/2017 10:09pm \n\n  CHP Incident 171115GG03413\n    https://www.google.com/maps/search/-122.071253,37.897511\n    Nov 15 2017 10:04PM  1183-Trfc Collision-Unkn Inj  I680 S / Olympic Blvd Ofr \n  Nov 15 2017 10:06PM [2] STANDING WATER IN #1 Nov 15 2017 10:06PM [1] BUMPER OFF VEH / IN CD / 2 GRY SD  Information courtesy of \n  Last updated: 11/15/2017 10:09pm \n\n  CHP Incident 171115GG03411\n    https://www.google.com/maps/search/-122.1426,37.486319\n    Nov 15 2017 10:04PM  20002-Hit and Run No Injuries  Sr84 / Sr109 \n  Nov 15 2017 10:07PM [6] LL W/ BRDG Nov 15 2017 10:07PM [5] BOTH VIC VEHS HAVE HAZ LIGHTS ON *** DRVRS OO VEHS STANDING ON RHS Nov 15 2017 10:06PM [4] 2ND VICT VEH:   BLK POSS VOLK GOLF  BLKG SLOW LANE Nov 15 2017 10:06PM [8] [Appended, 22:07:56] [2] BLKG #2-3 Nov 15 2017 10:06PM [7] [Appended, 22:07:56] [1] BLK VOLK JETTA VS GLD TOYT CAM VS UNK THAT DROVE OFFNov 15 2017 10:05PM [3] VICT VEH:   SIL TOYT CAMRY  **  BLKG MIDDLE LANE Nov 15 2017 10:05PM [1] AT THE BEGINNING OF BRDG  Information courtesy of \n  Last updated: 11/15/2017 10:09pm \n\n  CHP Incident 171115BC01326\n    https://www.google.com/maps/search/-117.162767,32.760387\n    Nov 15 2017 10:06PM  SIG Alert  Sr163 N / Sr163 N I8 E Con \n   Information courtesy of \n  Last updated: 11/15/2017 10:09pm \n\n  CHP Incident 171115OC00831\n    https://www.google.com/maps/search/-118.037829,33.772106\n    Nov 15 2017 10:06PM  1125-Traffic Hazard  I405 S / Valley View St Onr \n  Nov 15 2017 10:07PM [1] BLU VW PASSAT IN CD  Information courtesy of \n  Last updated: 11/15/2017 10:09pm\n\n1 incident removed:\n  CHP Incident 171115GG03297\n    https://www.google.com/maps/search/-122.294033,37.830511\n    Nov 15 2017  9:15PM  1183-Trfc Collision-Unkn Inj  I80 W / Powell St E Onr \n  Nov 15 2017  9:41PM [18] [Rotation Request Comment] 1039 EAST BAY TOW 888-204-5509 SD 855Nov 15 2017  9:39PM [17] B96-080  1185 FOR CHEV W/MAJ FE DAMAGENov 15 2017  9:26PM [16] B96-080  2 VEH 1182 / BOX TRK WAS FRM EARLIER TCNov 15 2017  9:24PM [15] B96-080  EVERYTHING TO RHS BTWN THE ASHBYS /// RDWY CLR BTWN HERE AND POWELLNov 15 2017  9:24PM [14] 1039 1141 1022 Nov 15 2017  9:22PM [12] 1039 1141Nov 15 2017  9:21PM [11] B96-080  W/CHEV AVEO IN #1Nov 15 2017  9:21PM [9] B96-080  97 W/ BREAK WB JEO ASHBYNov 15 2017  9:20PM [8] WHI BOX TRUCK  AND   2 UNKS SD'S  //   RHS Nov 15 2017  9:19PM [7] BLK HOND SD  //  LN #1Nov 15 2017  9:17PM [4] SOLO VEH BLKG #1  Information courtesy of \n  Last updated: 11/15/2017 10:06pm","distinct":true,"url":"https://api.github.com/repos/simonw/disaster-data/commits/40c218146edf1350f78b2114f170c9556a433b59"}]},"public":true,"created_at":"2017-11-16T06:09:35Z"},{"id":"6862547914","type":"GollumEvent","actor":{"id":12675339,"login":"stefaneidelloth","display_login":"stefaneidelloth","gravatar_id":"","url":"https://api.github.com/users/stefaneidelloth","avatar_url":"https://avatars.githubusercontent.com/u/12675339?"},"repo":{"id":104259641,"name":"stefaneidelloth/matameko","url":"https://api.github.com/repos/stefaneidelloth/matameko"},"payload":{"pages":[{"page_name":"Bedürfnis-Charts","title":"Bedürfnis Charts","summary":null,"action":"edited","sha":"8cd701b4c4a948153fae6ace50e612d97d0ce13e","html_url":"https://github.com/stefaneidelloth/matameko/wiki/Bed%C3%BCrfnis-Charts"}]},"public":true,"created_at":"2017-11-16T06:09:35Z"},{"id":"6862547907","type":"PushEvent","actor":{"id":20119474,"login":"ghostdsb","display_login":"ghostdsb","gravatar_id":"","url":"https://api.github.com/users/ghostdsb","avatar_url":"https://avatars.githubusercontent.com/u/20119474?"},"repo":{"id":110440278,"name":"ghostdsb/Bet-Tac-Toe","url":"https://api.github.com/repos/ghostdsb/Bet-Tac-Toe"},"payload":{"push_id":2128121518,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"253ef4c47e95f545a3c045ec71f4bb046b8b7618","before":"8c519951a7514b01f4078faf12da6d746b748a80","commits":[{"sha":"253ef4c47e95f545a3c045ec71f4bb046b8b7618","author":{"email":"dibyanshu.bhoi@gmail.com","name":"Dibyanshu Bhoi"},"message":"Add files via upload","distinct":true,"url":"https://api.github.com/repos/ghostdsb/Bet-Tac-Toe/commits/253ef4c47e95f545a3c045ec71f4bb046b8b7618"}]},"public":true,"created_at":"2017-11-16T06:09:35Z"},{"id":"6862547904","type":"PushEvent","actor":{"id":33614751,"login":"Alx261","display_login":"Alx261","gravatar_id":"","url":"https://api.github.com/users/Alx261","avatar_url":"https://avatars.githubusercontent.com/u/33614751?"},"repo":{"id":110923021,"name":"Alx261/Prueba","url":"https://api.github.com/repos/Alx261/Prueba"},"payload":{"push_id":2128121517,"size":3,"distinct_size":2,"ref":"refs/heads/master","head":"398289c299b0d3a7a8186439ee6ed90a7451f77a","before":"d072f92116c2b60094f50a2e384923a0d9b777f6","commits":[{"sha":"b4c0d88fab8e1d01ee79c9f87c6b3b27b90fb926","author":{"email":"aleja@LAPTOP-L4GOIRMA","name":"aleja"},"message":"Merge master into Desarrollo","distinct":false,"url":"https://api.github.com/repos/Alx261/Prueba/commits/b4c0d88fab8e1d01ee79c9f87c6b3b27b90fb926"},{"sha":"3fd1a07e51888c4248dc7b1d95b522fbd5a3cc44","author":{"email":"aleja@LAPTOP-L4GOIRMA","name":"aleja"},"message":"Merge origin/Desarrollo\n\nConflicts:\n\tPhpProject1/index.php","distinct":true,"url":"https://api.github.com/repos/Alx261/Prueba/commits/3fd1a07e51888c4248dc7b1d95b522fbd5a3cc44"},{"sha":"398289c299b0d3a7a8186439ee6ed90a7451f77a","author":{"email":"aleja@LAPTOP-L4GOIRMA","name":"aleja"},"message":"Merge origin/Desarrollo","distinct":true,"url":"https://api.github.com/repos/Alx261/Prueba/commits/398289c299b0d3a7a8186439ee6ed90a7451f77a"}]},"public":true,"created_at":"2017-11-16T06:09:35Z"},{"id":"6862547901","type":"WatchEvent","actor":{"id":10556814,"login":"zetbaitsu","display_login":"zetbaitsu","gravatar_id":"","url":"https://api.github.com/users/zetbaitsu","avatar_url":"https://avatars.githubusercontent.com/u/10556814?"},"repo":{"id":71638146,"name":"theredfoxfire/react-native-dropdown-modal","url":"https://api.github.com/repos/theredfoxfire/react-native-dropdown-modal"},"payload":{"action":"started"},"public":true,"created_at":"2017-11-16T06:09:35Z"},{"id":"6862547899","type":"PushEvent","actor":{"id":307049,"login":"franck-paul","display_login":"franck-paul","gravatar_id":"","url":"https://api.github.com/users/franck-paul","avatar_url":"https://avatars.githubusercontent.com/u/307049?"},"repo":{"id":109299023,"name":"dotclear/dotclear","url":"https://api.github.com/repos/dotclear/dotclear"},"payload":{"push_id":2128121515,"size":0,"distinct_size":0,"ref":"refs/heads/2.9","head":"982ee0730bc08d4dc5364f96aaea7fd803c05d47","before":"982ee0730bc08d4dc5364f96aaea7fd803c05d47","commits":[]},"public":true,"created_at":"2017-11-16T06:09:35Z","org":{"id":4987633,"login":"dotclear","gravatar_id":"","url":"https://api.github.com/orgs/dotclear","avatar_url":"https://avatars.githubusercontent.com/u/4987633?"}},{"id":"6862547896","type":"PushEvent","actor":{"id":8517910,"login":"LombiqBot","display_login":"LombiqBot","gravatar_id":"","url":"https://api.github.com/users/LombiqBot","avatar_url":"https://avatars.githubusercontent.com/u/8517910?"},"repo":{"id":46632135,"name":"Lombiq/Orchard-Token-Title","url":"https://api.github.com/repos/Lombiq/Orchard-Token-Title"},"payload":{"push_id":2128121512,"size":0,"distinct_size":0,"ref":"refs/heads/orchard-upgrade-1.9.1","head":"ac739f0b9b0ab9d5a125818902d4f92b63eb028c","before":"ac739f0b9b0ab9d5a125818902d4f92b63eb028c","commits":[]},"public":true,"created_at":"2017-11-16T06:09:34Z","org":{"id":8158177,"login":"Lombiq","gravatar_id":"","url":"https://api.github.com/orgs/Lombiq","avatar_url":"https://avatars.githubusercontent.com/u/8158177?"}},{"id":"6862547895","type":"GollumEvent","actor":{"id":13864406,"login":"mayudong1","display_login":"mayudong1","gravatar_id":"","url":"https://api.github.com/users/mayudong1","avatar_url":"https://avatars.githubusercontent.com/u/13864406?"},"repo":{"id":48353453,"name":"ksvc/KSYMediaPlayer_iOS","url":"https://api.github.com/repos/ksvc/KSYMediaPlayer_iOS"},"payload":{"pages":[{"page_name":"decoderMode","title":"decoderMode","summary":null,"action":"edited","sha":"c1ec2d443df335dda2977fa401a38c147e129fda","html_url":"https://github.com/ksvc/KSYMediaPlayer_iOS/wiki/decoderMode"}]},"public":true,"created_at":"2017-11-16T06:09:34Z","org":{"id":16359966,"login":"ksvc","gravatar_id":"","url":"https://api.github.com/orgs/ksvc","avatar_url":"https://avatars.githubusercontent.com/u/16359966?"}},{"id":"6862547890","type":"WatchEvent","actor":{"id":20514086,"login":"AlexXiong97","display_login":"AlexXiong97","gravatar_id":"","url":"https://api.github.com/users/AlexXiong97","avatar_url":"https://avatars.githubusercontent.com/u/20514086?"},"repo":{"id":35723130,"name":"paldepind/functional-frontend-architecture","url":"https://api.github.com/repos/paldepind/functional-frontend-architecture"},"payload":{"action":"started"},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547889","type":"PushEvent","actor":{"id":31842492,"login":"rocf1y","display_login":"rocf1y","gravatar_id":"","url":"https://api.github.com/users/rocf1y","avatar_url":"https://avatars.githubusercontent.com/u/31842492?"},"repo":{"id":110139151,"name":"rocf1y/test","url":"https://api.github.com/repos/rocf1y/test"},"payload":{"push_id":2128121509,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"fcc0c0fbed36c66e0e6e3de2c65010c3bab21a37","before":"b86c2a098719e27ab583fea193c9f91dc30fc9b0","commits":[{"sha":"fcc0c0fbed36c66e0e6e3de2c65010c3bab21a37","author":{"email":"914075513@qq.com","name":"LiangMo"},"message":"test fifth commit","distinct":true,"url":"https://api.github.com/repos/rocf1y/test/commits/fcc0c0fbed36c66e0e6e3de2c65010c3bab21a37"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547885","type":"WatchEvent","actor":{"id":16992520,"login":"Ibrahimhass","display_login":"Ibrahimhass","gravatar_id":"","url":"https://api.github.com/users/Ibrahimhass","avatar_url":"https://avatars.githubusercontent.com/u/16992520?"},"repo":{"id":106708680,"name":"davidseek/Thumbnail-From-Video-Swift","url":"https://api.github.com/repos/davidseek/Thumbnail-From-Video-Swift"},"payload":{"action":"started"},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547883","type":"PushEvent","actor":{"id":4255998,"login":"marynavoitenko","display_login":"marynavoitenko","gravatar_id":"","url":"https://api.github.com/users/marynavoitenko","avatar_url":"https://avatars.githubusercontent.com/u/4255998?"},"repo":{"id":110925009,"name":"marynavoitenko/oo-my-pets-v-000","url":"https://api.github.com/repos/marynavoitenko/oo-my-pets-v-000"},"payload":{"push_id":2128121505,"size":1,"distinct_size":1,"ref":"refs/heads/wip","head":"f04f5c47fccab87b633cc98f5f026a1c2ecbd61a","before":"83973f2841f959ab5f3f3f3b9b02d45f81eb9ba5","commits":[{"sha":"f04f5c47fccab87b633cc98f5f026a1c2ecbd61a","author":{"email":"maryna.voitenko@gmail.com","name":"Maryna Voitenko"},"message":"automatically backed up by learn","distinct":true,"url":"https://api.github.com/repos/marynavoitenko/oo-my-pets-v-000/commits/f04f5c47fccab87b633cc98f5f026a1c2ecbd61a"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547880","type":"PushEvent","actor":{"id":4324588,"login":"srdo","display_login":"srdo","gravatar_id":"","url":"https://api.github.com/users/srdo","avatar_url":"https://avatars.githubusercontent.com/u/4324588?"},"repo":{"id":51674503,"name":"srdo/storm","url":"https://api.github.com/repos/srdo/storm"},"payload":{"push_id":2128121503,"size":1,"distinct_size":1,"ref":"refs/heads/STORM-2546-1.x","head":"d9fe768a9f7cb47bb2b75a26e81676fc69b1fde0","before":"85e32f946a17bdfdb8e975d9724492da59327f78","commits":[{"sha":"d9fe768a9f7cb47bb2b75a26e81676fc69b1fde0","author":{"email":"srdo@apache.org","name":"Stig Rohde Døssing"},"message":"STORM-2546: Fix storm-kafka-client spout getting stuck when retriable offsets were deleted from the Kafka log due to topic compaction","distinct":true,"url":"https://api.github.com/repos/srdo/storm/commits/d9fe768a9f7cb47bb2b75a26e81676fc69b1fde0"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547874","type":"PushEvent","actor":{"id":15374198,"login":"kyleschmid","display_login":"kyleschmid","gravatar_id":"","url":"https://api.github.com/users/kyleschmid","avatar_url":"https://avatars.githubusercontent.com/u/15374198?"},"repo":{"id":109728139,"name":"kyleschmid/ObjectMerge","url":"https://api.github.com/repos/kyleschmid/ObjectMerge"},"payload":{"push_id":2128121499,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"172bf26a15a915c5ec748ab63687d0debbfef8ff","before":"a065d87bf1c8c3648906d485282ffb426ef67d96","commits":[{"sha":"172bf26a15a915c5ec748ab63687d0debbfef8ff","author":{"email":"kyleschmid@kyles-mbp-2.attlocal.net","name":"Kyle Schmid"},"message":"Resolve possible chunking error","distinct":true,"url":"https://api.github.com/repos/kyleschmid/ObjectMerge/commits/172bf26a15a915c5ec748ab63687d0debbfef8ff"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547872","type":"PushEvent","actor":{"id":30596385,"login":"mansi-webpatriot","display_login":"mansi-webpatriot","gravatar_id":"","url":"https://api.github.com/users/mansi-webpatriot","avatar_url":"https://avatars.githubusercontent.com/u/30596385?"},"repo":{"id":99931596,"name":"priyankamackwan/fitnesstips","url":"https://api.github.com/repos/priyankamackwan/fitnesstips"},"payload":{"push_id":2128121498,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"9782282eeceee2fa1a24d0229fc1753a6721011e","before":"a99b49c703dd9c080b0e1505a13a1869ceb4333b","commits":[{"sha":"9782282eeceee2fa1a24d0229fc1753a6721011e","author":{"email":"mansi.webpatriot@gmail.com","name":"mansi"},"message":"add view button in category->articles","distinct":true,"url":"https://api.github.com/repos/priyankamackwan/fitnesstips/commits/9782282eeceee2fa1a24d0229fc1753a6721011e"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547868","type":"PushEvent","actor":{"id":24778360,"login":"vermeer-1977","display_login":"vermeer-1977","gravatar_id":"","url":"https://api.github.com/users/vermeer-1977","avatar_url":"https://avatars.githubusercontent.com/u/24778360?"},"repo":{"id":102561789,"name":"vermeerlab/maven","url":"https://api.github.com/repos/vermeerlab/maven"},"payload":{"push_id":2128121495,"size":1,"distinct_size":1,"ref":"refs/heads/mvn-repo","head":"79c52afbc822ae00f5d3a978b6eace55459d00f9","before":"0d01ba9aef25a027e54085b0208fd18c5b4cf5e8","commits":[{"sha":"79c52afbc822ae00f5d3a978b6eace55459d00f9","author":{"email":"vermeer.1977.blog@gmail.com","name":"_vermeer_"},"message":"Maven artifacts for vermeerlab-classpath-scanner-0.3.0","distinct":true,"url":"https://api.github.com/repos/vermeerlab/maven/commits/79c52afbc822ae00f5d3a978b6eace55459d00f9"}]},"public":true,"created_at":"2017-11-16T06:09:34Z","org":{"id":31536313,"login":"vermeerlab","gravatar_id":"","url":"https://api.github.com/orgs/vermeerlab","avatar_url":"https://avatars.githubusercontent.com/u/31536313?"}},{"id":"6862547865","type":"IssuesEvent","actor":{"id":18279056,"login":"ashleyse2016","display_login":"ashleyse2016","gravatar_id":"","url":"https://api.github.com/users/ashleyse2016","avatar_url":"https://avatars.githubusercontent.com/u/18279056?"},"repo":{"id":51461015,"name":"SpamExperts/cpanel-addon","url":"https://api.github.com/repos/SpamExperts/cpanel-addon"},"payload":{"action":"reopened","issue":{"url":"https://api.github.com/repos/SpamExperts/cpanel-addon/issues/37","repository_url":"https://api.github.com/repos/SpamExperts/cpanel-addon","labels_url":"https://api.github.com/repos/SpamExperts/cpanel-addon/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/SpamExperts/cpanel-addon/issues/37/comments","events_url":"https://api.github.com/repos/SpamExperts/cpanel-addon/issues/37/events","html_url":"https://github.com/SpamExperts/cpanel-addon/issues/37","id":272478702,"number":37,"title":"This feature is not available for your account - with zend fatal error","user":{"login":"ashleyse2016","id":18279056,"avatar_url":"https://avatars2.githubusercontent.com/u/18279056?v=4","gravatar_id":"","url":"https://api.github.com/users/ashleyse2016","html_url":"https://github.com/ashleyse2016","followers_url":"https://api.github.com/users/ashleyse2016/followers","following_url":"https://api.github.com/users/ashleyse2016/following{/other_user}","gists_url":"https://api.github.com/users/ashleyse2016/gists{/gist_id}","starred_url":"https://api.github.com/users/ashleyse2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashleyse2016/subscriptions","organizations_url":"https://api.github.com/users/ashleyse2016/orgs","repos_url":"https://api.github.com/users/ashleyse2016/repos","events_url":"https://api.github.com/users/ashleyse2016/events{/privacy}","received_events_url":"https://api.github.com/users/ashleyse2016/received_events","type":"User","site_admin":false},"labels":[{"id":324260303,"url":"https://api.github.com/repos/SpamExperts/cpanel-addon/labels/bug","name":"bug","color":"fc2929","default":true},{"id":544296615,"url":"https://api.github.com/repos/SpamExperts/cpanel-addon/labels/priority-normal","name":"priority-normal","color":"006b75","default":false},{"id":418080963,"url":"https://api.github.com/repos/SpamExperts/cpanel-addon/labels/testing","name":"testing","color":"eb6420","default":false}],"state":"open","locked":false,"assignee":{"login":"for93t","id":2736458,"avatar_url":"https://avatars0.githubusercontent.com/u/2736458?v=4","gravatar_id":"","url":"https://api.github.com/users/for93t","html_url":"https://github.com/for93t","followers_url":"https://api.github.com/users/for93t/followers","following_url":"https://api.github.com/users/for93t/following{/other_user}","gists_url":"https://api.github.com/users/for93t/gists{/gist_id}","starred_url":"https://api.github.com/users/for93t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/for93t/subscriptions","organizations_url":"https://api.github.com/users/for93t/orgs","repos_url":"https://api.github.com/users/for93t/repos","events_url":"https://api.github.com/users/for93t/events{/privacy}","received_events_url":"https://api.github.com/users/for93t/received_events","type":"User","site_admin":false},"assignees":[{"login":"for93t","id":2736458,"avatar_url":"https://avatars0.githubusercontent.com/u/2736458?v=4","gravatar_id":"","url":"https://api.github.com/users/for93t","html_url":"https://github.com/for93t","followers_url":"https://api.github.com/users/for93t/followers","following_url":"https://api.github.com/users/for93t/following{/other_user}","gists_url":"https://api.github.com/users/for93t/gists{/gist_id}","starred_url":"https://api.github.com/users/for93t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/for93t/subscriptions","organizations_url":"https://api.github.com/users/for93t/orgs","repos_url":"https://api.github.com/users/for93t/repos","events_url":"https://api.github.com/users/for93t/events{/privacy}","received_events_url":"https://api.github.com/users/for93t/received_events","type":"User","site_admin":false},{"login":"Agoodfella","id":12559294,"avatar_url":"https://avatars3.githubusercontent.com/u/12559294?v=4","gravatar_id":"","url":"https://api.github.com/users/Agoodfella","html_url":"https://github.com/Agoodfella","followers_url":"https://api.github.com/users/Agoodfella/followers","following_url":"https://api.github.com/users/Agoodfella/following{/other_user}","gists_url":"https://api.github.com/users/Agoodfella/gists{/gist_id}","starred_url":"https://api.github.com/users/Agoodfella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Agoodfella/subscriptions","organizations_url":"https://api.github.com/users/Agoodfella/orgs","repos_url":"https://api.github.com/users/Agoodfella/repos","events_url":"https://api.github.com/users/Agoodfella/events{/privacy}","received_events_url":"https://api.github.com/users/Agoodfella/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2017-11-09T08:34:48Z","updated_at":"2017-11-16T06:09:34Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"### Version information\r\n\r\n```\r\nControlpanel: Cpanel v11.68.0.12\r\nPHP version: 5.6.30\r\nAddon version: 3.0.96549\r\n```\r\n\r\n### Steps to replicate\r\n\r\n 1. Login to WHM server\r\n 2. Navigate to list domains\r\n 3. On screen error\r\n\r\n1. navigate to cPanel user\r\n2. Click Professional spam filter\r\n3. On screen indicates `This feature is not available for your account`\r\n\r\nThere is no addon log when this happens. \r\n\r\n### Actual result\r\n\r\n```\r\nFatal error: Uncaught exception 'Zend_Session_Exception' with message 'You must explicitly start the session with Zend_Session::start() when session options are set to strict.' in /usr/local/prospamfilter/library/Zend/Session.php:436 Stack trace: #0 /usr/local/prospamfilter/library/Zend/Session/Namespace.php(143): Zend_Session::start(true) #1 /usr/local/prospamfilter/library/Zend/Controller/Action/Helper/FlashMessenger.php(82): Zend_Session_Namespace->__construct('FlashMessenger') #2 /usr/local/prospamfilter/interfaces/admin.php(66): Zend_Controller_Action_Helper_FlashMessenger->__construct() #3 /usr/local/prospamfilter/frontend/whm/prospamfilter.php(35): require_once('/usr/local/pros...') #4 {main} thrown in /usr/local/prospamfilter/library/Zend/Session.php on line 436\r\n```\r\n\r\n\r\n### Expected result\r\n\r\nList all domains, and also cPanel user level list domains should work. \r\n\r\n### Other notes\r\n\r\nAdded logging from client\r\n\r\n```\r\n[2017-11-07 05:05:59 -0500] info [xml-api] Permission denied: You do not have the required privileges to run “verify_user_has_feature”. [verify_user_has_feature] version [1].\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\nCannot get grandparent of grandparent process name.\r\n[2017-11-07 05:06:40 -0500] info [xml-api] Permission denied: You do not have the required privileges to run “verify_user_has_feature”. [verify_user_has_feature] version [1].\r\n[2017-11-07 05:08:49 -0500] warn [pureauth] Failed to call hulk pre_login for anonymous@REDACTED  (system) at bin/pureauth.pl line 135.\r\n[07-Nov-2017 10:25:44 UTC] PHP Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'You must explicitly start the session with Zend_Session::start() when session options are set to strict.' in /usr/local/prospamfilter/library/Zend/Session.php:436\r\nStack trace:\r\n#0 /usr/local/prospamfilter/library/Zend/Session/Namespace.php(143): Zend_Session::start(true)\r\n#1 /usr/local/prospamfilter/library/Zend/Controller/Action/Helper/FlashMessenger.php(82): Zend_Session_Namespace->__construct('FlashMessenger')\r\n#2 /usr/local/prospamfilter/interfaces/admin.php(66): Zend_Controller_Action_Helper_FlashMessenger->__construct()\r\n#3 /usr/local/prospamfilter/frontend/whm/prospamfilter.php(35): require_once('/usr/local/pros...')\r\n#4 {main}\r\nthrown in /usr/local/prospamfilter/library/Zend/Session.php on line 436\r\n[2017-11-07 05:25:44 -0500] warn [whostmgrd] The subprocess (/usr/local/cpanel/whostmgr/docroot/cgi/addon_prospamfilter.cgi) exited with an error: The subprocess reported error number 255 when it ended. at /usr/local/cpanel/Cpanel/Server/Handlers/SubProcess.pm line 251.\r\nCpanel::Server::Handlers::SubProcess::_report_subprocess_errors(Cpanel::Server::Handlers::SubProcess=HASH(0x1fbdb38)) called at /usr/local/cpanel/Cpanel/Server/Handlers/SubProcess.pm line 109\r\nCpanel::Server::Handlers::SubProcess::handler(Cpanel::Server::Handlers::SubProcess=HASH(0x1fbdb38), __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, 822722, __CPANEL_HIDDEN__, IO::Handle=GLOB(0x1fbda18), __CPANEL_HIDDEN__, ...) called at cpsrvd.pl line 6511\r\ncpanel::cpsrvd::cgiHandler(__CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__, __CPANEL_HIDDEN__) called at cpsrvd.pl line 5981\r\ncpanel::cpsrvd::dodoc_whostmgrd() called at cpsrvd.pl line 1651\r\ncpanel::cpsrvd::dodoc(HASH(0x14efd00)) called at cpsrvd.pl line 1429\r\ncpanel::cpsrvd::handle_one_connection(7) called at cpsrvd.pl line 877\r\ncpanel::cpsrvd::script() called at cpsrvd.pl line 324\r\nwarn [whostmgrd] The subprocess (/usr/local/cpanel/whostmgr/docroot/cgi/addon_prospamfilter.cgi) exited with an error: The subprocess reported error number 255 when it ended.\r\nPHP Fatal error: Call to a member function whm_api() on null in /usr/local/prospamfilter/library/SpamFilter/PanelSupport/Cpanel.php on line 1645\r\n```"}},"public":true,"created_at":"2017-11-16T06:09:34Z","org":{"id":7713176,"login":"SpamExperts","gravatar_id":"","url":"https://api.github.com/orgs/SpamExperts","avatar_url":"https://avatars.githubusercontent.com/u/7713176?"}},{"id":"6862547857","type":"PushEvent","actor":{"id":19200169,"login":"gourgopal","display_login":"gourgopal","gravatar_id":"","url":"https://api.github.com/users/gourgopal","avatar_url":"https://avatars.githubusercontent.com/u/19200169?"},"repo":{"id":110717735,"name":"gourgopal/ng-bday23","url":"https://api.github.com/repos/gourgopal/ng-bday23"},"payload":{"push_id":2128121491,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"693829cc11022cfa01ac47baeb6e8a3033cbace9","before":"0ca8538274361b0d4999f1c76ca1a2cf6f61bbfc","commits":[{"sha":"693829cc11022cfa01ac47baeb6e8a3033cbace9","author":{"email":"gourgopal@outlook.com","name":"Gour Gopal"},"message":"added typing animation","distinct":true,"url":"https://api.github.com/repos/gourgopal/ng-bday23/commits/693829cc11022cfa01ac47baeb6e8a3033cbace9"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547854","type":"PushEvent","actor":{"id":961165,"login":"kyubuns","display_login":"kyubuns","gravatar_id":"","url":"https://api.github.com/users/kyubuns","avatar_url":"https://avatars.githubusercontent.com/u/961165?"},"repo":{"id":88358748,"name":"kyubuns/Baum2","url":"https://api.github.com/repos/kyubuns/Baum2"},"payload":{"push_id":2128121489,"size":6,"distinct_size":6,"ref":"refs/heads/master","head":"5faeb2ee8d87b9471c9e2fda357ab7d437119d3c","before":"5380a1c7e86328c6159ac239ab7a080a1ce41b7a","commits":[{"sha":"835381db5812e7532918dc0dcb43fe77bf150708","author":{"email":"kyubuns@gmail.com","name":"kyubuns"},"message":"タブ派やめました","distinct":true,"url":"https://api.github.com/repos/kyubuns/Baum2/commits/835381db5812e7532918dc0dcb43fe77bf150708"},{"sha":"32e71369e2ffe8592a04623c4b049f74975bad64","author":{"email":"kyubuns@gmail.com","name":"kyubuns"},"message":"Unity2017.2.0p1","distinct":true,"url":"https://api.github.com/repos/kyubuns/Baum2/commits/32e71369e2ffe8592a04623c4b049f74975bad64"},{"sha":"bc87d6e07d4ae43c51db89ac56d86784ed7d3dc9","author":{"email":"kyubuns@gmail.com","name":"kyubuns"},"message":"rider","distinct":true,"url":"https://api.github.com/repos/kyubuns/Baum2/commits/bc87d6e07d4ae43c51db89ac56d86784ed7d3dc9"},{"sha":"89f4b70149b3d50c159d020d95ea86a1eec51142","author":{"email":"kyubuns@gmail.com","name":"kyubuns"},"message":"今更直せないしlowerCamel","distinct":true,"url":"https://api.github.com/repos/kyubuns/Baum2/commits/89f4b70149b3d50c159d020d95ea86a1eec51142"},{"sha":"9f85f7357b37cff4b3baeda72c329dff5da4abd1","author":{"email":"kyubuns@gmail.com","name":"kyubuns"},"message":"変なテキスト残ってた","distinct":true,"url":"https://api.github.com/repos/kyubuns/Baum2/commits/9f85f7357b37cff4b3baeda72c329dff5da4abd1"},{"sha":"5faeb2ee8d87b9471c9e2fda357ab7d437119d3c","author":{"email":"kyubuns@gmail.com","name":"kyubuns"},"message":"リファクタ","distinct":true,"url":"https://api.github.com/repos/kyubuns/Baum2/commits/5faeb2ee8d87b9471c9e2fda357ab7d437119d3c"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547852","type":"PushEvent","actor":{"id":18349159,"login":"ksyydream","display_login":"ksyydream","gravatar_id":"","url":"https://api.github.com/users/ksyydream","avatar_url":"https://avatars.githubusercontent.com/u/18349159?"},"repo":{"id":108838088,"name":"ksyydream/ksls_2","url":"https://api.github.com/repos/ksyydream/ksls_2"},"payload":{"push_id":2128121488,"size":2,"distinct_size":2,"ref":"refs/heads/master","head":"71a72a27bf36b64b54ed460cc4f1bcaa1830be04","before":"e83fa022c91761f8a9dbe08c91ff4e706e6089d6","commits":[{"sha":"b4039238cd5a967a93087305b725dfccdb18a8a0","author":{"email":"249499109@qq.com","name":"ksyydream"},"message":"20171107","distinct":true,"url":"https://api.github.com/repos/ksyydream/ksls_2/commits/b4039238cd5a967a93087305b725dfccdb18a8a0"},{"sha":"71a72a27bf36b64b54ed460cc4f1bcaa1830be04","author":{"email":"249499109@qq.com","name":"ksyydream"},"message":"Merge branch 'master' of https://github.com/ksyydream/ksls_2","distinct":true,"url":"https://api.github.com/repos/ksyydream/ksls_2/commits/71a72a27bf36b64b54ed460cc4f1bcaa1830be04"}]},"public":true,"created_at":"2017-11-16T06:09:34Z"},{"id":"6862547837","type":"CreateEvent","actor":{"id":30554524,"login":"lilinho","display_login":"lilinho","gravatar_id":"","url":"https://api.github.com/users/lilinho","avatar_url":"https://avatars.githubusercontent.com/u/30554524?"},"repo":{"id":110930708,"name":"lilinho/kodilla_m11","url":"https://api.github.com/repos/lilinho/kodilla_m11"},"payload":{"ref":null,"ref_type":"repository","master_branch":"master","description":null,"pusher_type":"user"},"public":true,"created_at":"2017-11-16T06:09:33Z"},{"id":"6862547836","type":"WatchEvent","actor":{"id":1745634,"login":"yo0x","display_login":"yo0x","gravatar_id":"","url":"https://api.github.com/users/yo0x","avatar_url":"https://avatars.githubusercontent.com/u/1745634?"},"repo":{"id":86122120,"name":"discordapp/lilliput","url":"https://api.github.com/repos/discordapp/lilliput"},"payload":{"action":"started"},"public":true,"created_at":"2017-11-16T06:09:33Z","org":{"id":1965106,"login":"discordapp","gravatar_id":"","url":"https://api.github.com/orgs/discordapp","avatar_url":"https://avatars.githubusercontent.com/u/1965106?"}},{"id":"6862547834","type":"PushEvent","actor":{"id":18797579,"login":"JesusAriasSobalvarro","display_login":"JesusAriasSobalvarro","gravatar_id":"","url":"https://api.github.com/users/JesusAriasSobalvarro","avatar_url":"https://avatars.githubusercontent.com/u/18797579?"},"repo":{"id":93280892,"name":"AllanNLopez/carry","url":"https://api.github.com/repos/AllanNLopez/carry"},"payload":{"push_id":2128121480,"size":2,"distinct_size":2,"ref":"refs/heads/master","head":"5efd38b48c62834c9f0bc6f1cf2554c0f82b0bd4","before":"8a7cfacfe31dfa16465bca8ad107f567f1bd3bff","commits":[{"sha":"431c8d6e207db8131f7dc3378472f1ee5f3b719e","author":{"email":"jesus.d.arias96@gmail.com","name":"Jesus Arias"},"message":"Geolocalizacion des-comentada!","distinct":true,"url":"https://api.github.com/repos/AllanNLopez/carry/commits/431c8d6e207db8131f7dc3378472f1ee5f3b719e"},{"sha":"5efd38b48c62834c9f0bc6f1cf2554c0f82b0bd4","author":{"email":"jesus.d.arias96@gmail.com","name":"Jesus Arias"},"message":"Merge branch 'master' of https://github.com/AllanNLopez/carry","distinct":true,"url":"https://api.github.com/repos/AllanNLopez/carry/commits/5efd38b48c62834c9f0bc6f1cf2554c0f82b0bd4"}]},"public":true,"created_at":"2017-11-16T06:09:33Z"},{"id":"6862547831","type":"WatchEvent","actor":{"id":13957238,"login":"mabbas1","display_login":"mabbas1","gravatar_id":"","url":"https://api.github.com/users/mabbas1","avatar_url":"https://avatars.githubusercontent.com/u/13957238?"},"repo":{"id":70875272,"name":"CodeforAustralia/VBAspecies","url":"https://api.github.com/repos/CodeforAustralia/VBAspecies"},"payload":{"action":"started"},"public":true,"created_at":"2017-11-16T06:09:33Z","org":{"id":2573081,"login":"CodeforAustralia","gravatar_id":"","url":"https://api.github.com/orgs/CodeforAustralia","avatar_url":"https://avatars.githubusercontent.com/u/2573081?"}},{"id":"6862547829","type":"CreateEvent","actor":{"id":22949886,"login":"dlbq","display_login":"dlbq","gravatar_id":"","url":"https://api.github.com/users/dlbq","avatar_url":"https://avatars.githubusercontent.com/u/22949886?"},"repo":{"id":110928851,"name":"dlbq/vue-admin-template","url":"https://api.github.com/repos/dlbq/vue-admin-template"},"payload":{"ref":"master","ref_type":"branch","master_branch":"master","description":null,"pusher_type":"user"},"public":true,"created_at":"2017-11-16T06:09:33Z"}]

In [21]:
# get the encoding
r.encoding


Out[21]:
'utf-8'

Binary Response Content

You can also access the response body as bytes for non text-requests. The gzip and deflate transfer-encodings are automatically decoded for you. For example to create an image from binary data returned by a request you can use the following code:

from PIL import Image
from io import BytesIO

i = Image.open(BytesIO.(r.content))

JSON Response Content


In [22]:
# get request
r = requests.get('https://api.github.com/events')
r.json()


Out[22]:
[{'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/30032489?',
   'display_login': 'lg5031200',
   'gravatar_id': '',
   'id': 30032489,
   'login': 'lg5031200',
   'url': 'https://api.github.com/users/lg5031200'},
  'created_at': '2017-11-16T06:13:37Z',
  'id': '6862559237',
  'payload': {'before': 'effcd2b21ff39710d5390a1f024d27c715e5270c',
   'commits': [{'author': {'email': 'lg5031200@gmail.com',
      'name': 'lg5031200'},
     'distinct': True,
     'message': '456',
     'sha': '6473e8b48adcf5cf77cac432fa41da96451567cb',
     'url': 'https://api.github.com/repos/lg5031200/LineBotTemplate/commits/6473e8b48adcf5cf77cac432fa41da96451567cb'}],
   'distinct_size': 1,
   'head': '6473e8b48adcf5cf77cac432fa41da96451567cb',
   'push_id': 2128127767,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 110917823,
   'name': 'lg5031200/LineBotTemplate',
   'url': 'https://api.github.com/repos/lg5031200/LineBotTemplate'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/23624198?',
   'display_login': 'king052188',
   'gravatar_id': '',
   'id': 23624198,
   'login': 'king052188',
   'url': 'https://api.github.com/users/king052188'},
  'created_at': '2017-11-16T06:13:37Z',
  'id': '6862559236',
  'payload': {'before': 'fc090ca60d98bd81411423657379e63e25a22959',
   'commits': [{'author': {'email': 'me@kpa21.info', 'name': 'king052188'},
     'distinct': True,
     'message': '10',
     'sha': '08051080820a8fed13bf8b28bfa1c9fbd78759c8',
     'url': 'https://api.github.com/repos/king052188/Laravel-Binary-v3/commits/08051080820a8fed13bf8b28bfa1c9fbd78759c8'}],
   'distinct_size': 1,
   'head': '08051080820a8fed13bf8b28bfa1c9fbd78759c8',
   'push_id': 2128127766,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 106383811,
   'name': 'king052188/Laravel-Binary-v3',
   'url': 'https://api.github.com/repos/king052188/Laravel-Binary-v3'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/8517910?',
   'display_login': 'LombiqBot',
   'gravatar_id': '',
   'id': 8517910,
   'login': 'LombiqBot',
   'url': 'https://api.github.com/users/LombiqBot'},
  'created_at': '2017-11-16T06:13:37Z',
  'id': '6862559235',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/8158177?',
   'gravatar_id': '',
   'id': 8158177,
   'login': 'Lombiq',
   'url': 'https://api.github.com/orgs/Lombiq'},
  'payload': {'before': '17dc5d0acae5506df300def2de11e477cf536f79',
   'commits': [],
   'distinct_size': 0,
   'head': '17dc5d0acae5506df300def2de11e477cf536f79',
   'push_id': 2128127765,
   'ref': 'refs/heads/dev',
   'size': 0},
  'public': True,
  'repo': {'id': 46624205,
   'name': 'Lombiq/Orchard-Application-Host-Sample',
   'url': 'https://api.github.com/repos/Lombiq/Orchard-Application-Host-Sample'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/3051331?',
   'display_login': 'seclark',
   'gravatar_id': '',
   'id': 3051331,
   'login': 'seclark',
   'url': 'https://api.github.com/users/seclark'},
  'created_at': '2017-11-16T06:13:37Z',
  'id': '6862559233',
  'payload': {'before': 'f4d58b81cab0eecee17aeafe4400b36fe7ff33b1',
   'commits': [{'author': {'email': 'susanclark19@gmail.com',
      'name': 'seclark'},
     'distinct': True,
     'message': 'test',
     'sha': 'bb46445b2f8b186a0882ecb6b6185e8ddb93c778',
     'url': 'https://api.github.com/repos/seclark/GalfaCuber/commits/bb46445b2f8b186a0882ecb6b6185e8ddb93c778'}],
   'distinct_size': 1,
   'head': 'bb46445b2f8b186a0882ecb6b6185e8ddb93c778',
   'push_id': 2128127764,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 107018695,
   'name': 'seclark/GalfaCuber',
   'url': 'https://api.github.com/repos/seclark/GalfaCuber'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/2724844?',
   'display_login': 'reeslo',
   'gravatar_id': '',
   'id': 2724844,
   'login': 'reeslo',
   'url': 'https://api.github.com/users/reeslo'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559232',
  'payload': {'action': 'started'},
  'public': True,
  'repo': {'id': 22577668,
   'name': 'iranianpep/ajax-live-search',
   'url': 'https://api.github.com/repos/iranianpep/ajax-live-search'},
  'type': 'WatchEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/8417910?',
   'display_login': 'banbara23',
   'gravatar_id': '',
   'id': 8417910,
   'login': 'banbara23',
   'url': 'https://api.github.com/users/banbara23'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559228',
  'payload': {'before': '22f62b1f11fd0150e08251336968ba1d4be7f829',
   'commits': [{'author': {'email': '8417910+banbara23@users.noreply.github.com',
      'name': 'ikemura'},
     'distinct': True,
     'message': '文言変更 ykf 運行 -> 通常運行',
     'sha': 'cf2be90ca366058f6900ea25898a7af82bb1cabf',
     'url': 'https://api.github.com/repos/banbara23/Yaimafuni-Backend/commits/cf2be90ca366058f6900ea25898a7af82bb1cabf'}],
   'distinct_size': 1,
   'head': 'cf2be90ca366058f6900ea25898a7af82bb1cabf',
   'push_id': 2128127760,
   'ref': 'refs/heads/develop',
   'size': 1},
  'public': True,
  'repo': {'id': 84534170,
   'name': 'banbara23/Yaimafuni-Backend',
   'url': 'https://api.github.com/repos/banbara23/Yaimafuni-Backend'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/18098478?',
   'display_login': '297854895',
   'gravatar_id': '',
   'id': 18098478,
   'login': '297854895',
   'url': 'https://api.github.com/users/297854895'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559227',
  'payload': {'before': 'eab04183d980d140e30c61e152a12301c480d867',
   'commits': [{'author': {'email': '297854895@qq.com', 'name': 'zhukecheng'},
     'distinct': True,
     'message': 'add\n\nadd',
     'sha': 'aba9380badf7b8a4e70bce4470d4dfc2d4a99697',
     'url': 'https://api.github.com/repos/297854895/demo/commits/aba9380badf7b8a4e70bce4470d4dfc2d4a99697'}],
   'distinct_size': 1,
   'head': 'aba9380badf7b8a4e70bce4470d4dfc2d4a99697',
   'push_id': 2128127759,
   'ref': 'refs/heads/zhukecheng',
   'size': 1},
  'public': True,
  'repo': {'id': 110914410,
   'name': '297854895/demo',
   'url': 'https://api.github.com/repos/297854895/demo'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/30062354?',
   'display_login': 'zjy1990',
   'gravatar_id': '',
   'id': 30062354,
   'login': 'zjy1990',
   'url': 'https://api.github.com/users/zjy1990'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559224',
  'payload': {'before': 'bf26e5c7acbafc8f5ba71c850458493a90626aef',
   'commits': [{'author': {'email': 'Jeremy@Jeremy-Macbook.local',
      'name': 'Jeremy'},
     'distinct': True,
     'message': '4 class',
     'sha': '31981a1768c024494fc944118cb034bbeefe5568',
     'url': 'https://api.github.com/repos/zjy1990/AFP-MachineLearning/commits/31981a1768c024494fc944118cb034bbeefe5568'}],
   'distinct_size': 1,
   'head': '31981a1768c024494fc944118cb034bbeefe5568',
   'push_id': 2128127757,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 105688442,
   'name': 'zjy1990/AFP-MachineLearning',
   'url': 'https://api.github.com/repos/zjy1990/AFP-MachineLearning'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/33602280?',
   'display_login': 'jshestova',
   'gravatar_id': '',
   'id': 33602280,
   'login': 'jshestova',
   'url': 'https://api.github.com/users/jshestova'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559220',
  'payload': {'action': 'opened',
   'number': 1,
   'pull_request': {'_links': {'comments': {'href': 'https://api.github.com/repos/jshestova/312075-nerds/issues/1/comments'},
     'commits': {'href': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/1/commits'},
     'html': {'href': 'https://github.com/jshestova/312075-nerds/pull/1'},
     'issue': {'href': 'https://api.github.com/repos/jshestova/312075-nerds/issues/1'},
     'review_comment': {'href': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/comments{/number}'},
     'review_comments': {'href': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/1/comments'},
     'self': {'href': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/1'},
     'statuses': {'href': 'https://api.github.com/repos/jshestova/312075-nerds/statuses/3cb1fc3ee6f47c29d009b4c97e69a4c173219cc6'}},
    'additions': 0,
    'assignee': None,
    'assignees': [],
    'author_association': 'OWNER',
    'base': {'label': 'jshestova:master',
     'ref': 'master',
     'repo': {'archive_url': 'https://api.github.com/repos/jshestova/312075-nerds/{archive_format}{/ref}',
      'archived': False,
      'assignees_url': 'https://api.github.com/repos/jshestova/312075-nerds/assignees{/user}',
      'blobs_url': 'https://api.github.com/repos/jshestova/312075-nerds/git/blobs{/sha}',
      'branches_url': 'https://api.github.com/repos/jshestova/312075-nerds/branches{/branch}',
      'clone_url': 'https://github.com/jshestova/312075-nerds.git',
      'collaborators_url': 'https://api.github.com/repos/jshestova/312075-nerds/collaborators{/collaborator}',
      'comments_url': 'https://api.github.com/repos/jshestova/312075-nerds/comments{/number}',
      'commits_url': 'https://api.github.com/repos/jshestova/312075-nerds/commits{/sha}',
      'compare_url': 'https://api.github.com/repos/jshestova/312075-nerds/compare/{base}...{head}',
      'contents_url': 'https://api.github.com/repos/jshestova/312075-nerds/contents/{+path}',
      'contributors_url': 'https://api.github.com/repos/jshestova/312075-nerds/contributors',
      'created_at': '2017-11-12T16:14:33Z',
      'default_branch': 'master',
      'deployments_url': 'https://api.github.com/repos/jshestova/312075-nerds/deployments',
      'description': 'Юля Шестова',
      'downloads_url': 'https://api.github.com/repos/jshestova/312075-nerds/downloads',
      'events_url': 'https://api.github.com/repos/jshestova/312075-nerds/events',
      'fork': True,
      'forks': 0,
      'forks_count': 0,
      'forks_url': 'https://api.github.com/repos/jshestova/312075-nerds/forks',
      'full_name': 'jshestova/312075-nerds',
      'git_commits_url': 'https://api.github.com/repos/jshestova/312075-nerds/git/commits{/sha}',
      'git_refs_url': 'https://api.github.com/repos/jshestova/312075-nerds/git/refs{/sha}',
      'git_tags_url': 'https://api.github.com/repos/jshestova/312075-nerds/git/tags{/sha}',
      'git_url': 'git://github.com/jshestova/312075-nerds.git',
      'has_downloads': False,
      'has_issues': False,
      'has_pages': False,
      'has_projects': True,
      'has_wiki': False,
      'homepage': None,
      'hooks_url': 'https://api.github.com/repos/jshestova/312075-nerds/hooks',
      'html_url': 'https://github.com/jshestova/312075-nerds',
      'id': 110447633,
      'issue_comment_url': 'https://api.github.com/repos/jshestova/312075-nerds/issues/comments{/number}',
      'issue_events_url': 'https://api.github.com/repos/jshestova/312075-nerds/issues/events{/number}',
      'issues_url': 'https://api.github.com/repos/jshestova/312075-nerds/issues{/number}',
      'keys_url': 'https://api.github.com/repos/jshestova/312075-nerds/keys{/key_id}',
      'labels_url': 'https://api.github.com/repos/jshestova/312075-nerds/labels{/name}',
      'language': 'HTML',
      'languages_url': 'https://api.github.com/repos/jshestova/312075-nerds/languages',
      'merges_url': 'https://api.github.com/repos/jshestova/312075-nerds/merges',
      'milestones_url': 'https://api.github.com/repos/jshestova/312075-nerds/milestones{/number}',
      'mirror_url': None,
      'name': '312075-nerds',
      'notifications_url': 'https://api.github.com/repos/jshestova/312075-nerds/notifications{?since,all,participating}',
      'open_issues': 1,
      'open_issues_count': 1,
      'owner': {'avatar_url': 'https://avatars3.githubusercontent.com/u/33602280?v=4',
       'events_url': 'https://api.github.com/users/jshestova/events{/privacy}',
       'followers_url': 'https://api.github.com/users/jshestova/followers',
       'following_url': 'https://api.github.com/users/jshestova/following{/other_user}',
       'gists_url': 'https://api.github.com/users/jshestova/gists{/gist_id}',
       'gravatar_id': '',
       'html_url': 'https://github.com/jshestova',
       'id': 33602280,
       'login': 'jshestova',
       'organizations_url': 'https://api.github.com/users/jshestova/orgs',
       'received_events_url': 'https://api.github.com/users/jshestova/received_events',
       'repos_url': 'https://api.github.com/users/jshestova/repos',
       'site_admin': False,
       'starred_url': 'https://api.github.com/users/jshestova/starred{/owner}{/repo}',
       'subscriptions_url': 'https://api.github.com/users/jshestova/subscriptions',
       'type': 'User',
       'url': 'https://api.github.com/users/jshestova'},
      'private': False,
      'pulls_url': 'https://api.github.com/repos/jshestova/312075-nerds/pulls{/number}',
      'pushed_at': '2017-11-16T06:12:27Z',
      'releases_url': 'https://api.github.com/repos/jshestova/312075-nerds/releases{/id}',
      'size': 4,
      'ssh_url': 'git@github.com:jshestova/312075-nerds.git',
      'stargazers_count': 0,
      'stargazers_url': 'https://api.github.com/repos/jshestova/312075-nerds/stargazers',
      'statuses_url': 'https://api.github.com/repos/jshestova/312075-nerds/statuses/{sha}',
      'subscribers_url': 'https://api.github.com/repos/jshestova/312075-nerds/subscribers',
      'subscription_url': 'https://api.github.com/repos/jshestova/312075-nerds/subscription',
      'svn_url': 'https://github.com/jshestova/312075-nerds',
      'tags_url': 'https://api.github.com/repos/jshestova/312075-nerds/tags',
      'teams_url': 'https://api.github.com/repos/jshestova/312075-nerds/teams',
      'trees_url': 'https://api.github.com/repos/jshestova/312075-nerds/git/trees{/sha}',
      'updated_at': '2017-11-12T16:14:34Z',
      'url': 'https://api.github.com/repos/jshestova/312075-nerds',
      'watchers': 0,
      'watchers_count': 0},
     'sha': 'a3a34efb495d92d6af873122fb095c27a398b66c',
     'user': {'avatar_url': 'https://avatars3.githubusercontent.com/u/33602280?v=4',
      'events_url': 'https://api.github.com/users/jshestova/events{/privacy}',
      'followers_url': 'https://api.github.com/users/jshestova/followers',
      'following_url': 'https://api.github.com/users/jshestova/following{/other_user}',
      'gists_url': 'https://api.github.com/users/jshestova/gists{/gist_id}',
      'gravatar_id': '',
      'html_url': 'https://github.com/jshestova',
      'id': 33602280,
      'login': 'jshestova',
      'organizations_url': 'https://api.github.com/users/jshestova/orgs',
      'received_events_url': 'https://api.github.com/users/jshestova/received_events',
      'repos_url': 'https://api.github.com/users/jshestova/repos',
      'site_admin': False,
      'starred_url': 'https://api.github.com/users/jshestova/starred{/owner}{/repo}',
      'subscriptions_url': 'https://api.github.com/users/jshestova/subscriptions',
      'type': 'User',
      'url': 'https://api.github.com/users/jshestova'}},
    'body': '',
    'changed_files': 0,
    'closed_at': None,
    'comments': 0,
    'comments_url': 'https://api.github.com/repos/jshestova/312075-nerds/issues/1/comments',
    'commits': 1,
    'commits_url': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/1/commits',
    'created_at': '2017-11-16T06:13:36Z',
    'deletions': 0,
    'diff_url': 'https://github.com/jshestova/312075-nerds/pull/1.diff',
    'head': {'label': 'htmlacademy-htmlcss:master',
     'ref': 'master',
     'repo': {'archive_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/{archive_format}{/ref}',
      'archived': False,
      'assignees_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/assignees{/user}',
      'blobs_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/git/blobs{/sha}',
      'branches_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/branches{/branch}',
      'clone_url': 'https://github.com/htmlacademy-htmlcss/312075-nerds.git',
      'collaborators_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/collaborators{/collaborator}',
      'comments_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/comments{/number}',
      'commits_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/commits{/sha}',
      'compare_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/compare/{base}...{head}',
      'contents_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/contents/{+path}',
      'contributors_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/contributors',
      'created_at': '2017-11-12T16:10:55Z',
      'default_branch': 'master',
      'deployments_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/deployments',
      'description': 'Юля Шестова',
      'downloads_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/downloads',
      'events_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/events',
      'fork': False,
      'forks': 1,
      'forks_count': 1,
      'forks_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/forks',
      'full_name': 'htmlacademy-htmlcss/312075-nerds',
      'git_commits_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/git/commits{/sha}',
      'git_refs_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/git/refs{/sha}',
      'git_tags_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/git/tags{/sha}',
      'git_url': 'git://github.com/htmlacademy-htmlcss/312075-nerds.git',
      'has_downloads': False,
      'has_issues': False,
      'has_pages': True,
      'has_projects': True,
      'has_wiki': False,
      'homepage': 'https://github.com/jshestova/312075-nerds',
      'hooks_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/hooks',
      'html_url': 'https://github.com/htmlacademy-htmlcss/312075-nerds',
      'id': 110447301,
      'issue_comment_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/issues/comments{/number}',
      'issue_events_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/issues/events{/number}',
      'issues_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/issues{/number}',
      'keys_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/keys{/key_id}',
      'labels_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/labels{/name}',
      'language': 'HTML',
      'languages_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/languages',
      'merges_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/merges',
      'milestones_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/milestones{/number}',
      'mirror_url': None,
      'name': '312075-nerds',
      'notifications_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/notifications{?since,all,participating}',
      'open_issues': 0,
      'open_issues_count': 0,
      'owner': {'avatar_url': 'https://avatars3.githubusercontent.com/u/16576942?v=4',
       'events_url': 'https://api.github.com/users/htmlacademy-htmlcss/events{/privacy}',
       'followers_url': 'https://api.github.com/users/htmlacademy-htmlcss/followers',
       'following_url': 'https://api.github.com/users/htmlacademy-htmlcss/following{/other_user}',
       'gists_url': 'https://api.github.com/users/htmlacademy-htmlcss/gists{/gist_id}',
       'gravatar_id': '',
       'html_url': 'https://github.com/htmlacademy-htmlcss',
       'id': 16576942,
       'login': 'htmlacademy-htmlcss',
       'organizations_url': 'https://api.github.com/users/htmlacademy-htmlcss/orgs',
       'received_events_url': 'https://api.github.com/users/htmlacademy-htmlcss/received_events',
       'repos_url': 'https://api.github.com/users/htmlacademy-htmlcss/repos',
       'site_admin': False,
       'starred_url': 'https://api.github.com/users/htmlacademy-htmlcss/starred{/owner}{/repo}',
       'subscriptions_url': 'https://api.github.com/users/htmlacademy-htmlcss/subscriptions',
       'type': 'Organization',
       'url': 'https://api.github.com/users/htmlacademy-htmlcss'},
      'private': False,
      'pulls_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/pulls{/number}',
      'pushed_at': '2017-11-12T20:20:07Z',
      'releases_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/releases{/id}',
      'size': 5,
      'ssh_url': 'git@github.com:htmlacademy-htmlcss/312075-nerds.git',
      'stargazers_count': 0,
      'stargazers_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/stargazers',
      'statuses_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/statuses/{sha}',
      'subscribers_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/subscribers',
      'subscription_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/subscription',
      'svn_url': 'https://github.com/htmlacademy-htmlcss/312075-nerds',
      'tags_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/tags',
      'teams_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/teams',
      'trees_url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds/git/trees{/sha}',
      'updated_at': '2017-11-12T16:35:17Z',
      'url': 'https://api.github.com/repos/htmlacademy-htmlcss/312075-nerds',
      'watchers': 0,
      'watchers_count': 0},
     'sha': '3cb1fc3ee6f47c29d009b4c97e69a4c173219cc6',
     'user': {'avatar_url': 'https://avatars3.githubusercontent.com/u/16576942?v=4',
      'events_url': 'https://api.github.com/users/htmlacademy-htmlcss/events{/privacy}',
      'followers_url': 'https://api.github.com/users/htmlacademy-htmlcss/followers',
      'following_url': 'https://api.github.com/users/htmlacademy-htmlcss/following{/other_user}',
      'gists_url': 'https://api.github.com/users/htmlacademy-htmlcss/gists{/gist_id}',
      'gravatar_id': '',
      'html_url': 'https://github.com/htmlacademy-htmlcss',
      'id': 16576942,
      'login': 'htmlacademy-htmlcss',
      'organizations_url': 'https://api.github.com/users/htmlacademy-htmlcss/orgs',
      'received_events_url': 'https://api.github.com/users/htmlacademy-htmlcss/received_events',
      'repos_url': 'https://api.github.com/users/htmlacademy-htmlcss/repos',
      'site_admin': False,
      'starred_url': 'https://api.github.com/users/htmlacademy-htmlcss/starred{/owner}{/repo}',
      'subscriptions_url': 'https://api.github.com/users/htmlacademy-htmlcss/subscriptions',
      'type': 'Organization',
      'url': 'https://api.github.com/users/htmlacademy-htmlcss'}},
    'html_url': 'https://github.com/jshestova/312075-nerds/pull/1',
    'id': 152959214,
    'issue_url': 'https://api.github.com/repos/jshestova/312075-nerds/issues/1',
    'locked': False,
    'maintainer_can_modify': False,
    'merge_commit_sha': None,
    'mergeable': None,
    'mergeable_state': 'unknown',
    'merged': False,
    'merged_at': None,
    'merged_by': None,
    'milestone': None,
    'number': 1,
    'patch_url': 'https://github.com/jshestova/312075-nerds/pull/1.patch',
    'rebaseable': None,
    'requested_reviewers': [],
    'review_comment_url': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/comments{/number}',
    'review_comments': 0,
    'review_comments_url': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/1/comments',
    'state': 'open',
    'statuses_url': 'https://api.github.com/repos/jshestova/312075-nerds/statuses/3cb1fc3ee6f47c29d009b4c97e69a4c173219cc6',
    'title': '#13 Начинаем разметку личного проекта',
    'updated_at': '2017-11-16T06:13:36Z',
    'url': 'https://api.github.com/repos/jshestova/312075-nerds/pulls/1',
    'user': {'avatar_url': 'https://avatars3.githubusercontent.com/u/33602280?v=4',
     'events_url': 'https://api.github.com/users/jshestova/events{/privacy}',
     'followers_url': 'https://api.github.com/users/jshestova/followers',
     'following_url': 'https://api.github.com/users/jshestova/following{/other_user}',
     'gists_url': 'https://api.github.com/users/jshestova/gists{/gist_id}',
     'gravatar_id': '',
     'html_url': 'https://github.com/jshestova',
     'id': 33602280,
     'login': 'jshestova',
     'organizations_url': 'https://api.github.com/users/jshestova/orgs',
     'received_events_url': 'https://api.github.com/users/jshestova/received_events',
     'repos_url': 'https://api.github.com/users/jshestova/repos',
     'site_admin': False,
     'starred_url': 'https://api.github.com/users/jshestova/starred{/owner}{/repo}',
     'subscriptions_url': 'https://api.github.com/users/jshestova/subscriptions',
     'type': 'User',
     'url': 'https://api.github.com/users/jshestova'}}},
  'public': True,
  'repo': {'id': 110447633,
   'name': 'jshestova/312075-nerds',
   'url': 'https://api.github.com/repos/jshestova/312075-nerds'},
  'type': 'PullRequestEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/37391?',
   'display_login': 'czb',
   'gravatar_id': '',
   'id': 37391,
   'login': 'czb',
   'url': 'https://api.github.com/users/czb'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559217',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/19537770?',
   'gravatar_id': '',
   'id': 19537770,
   'login': 'bigclownlabs',
   'url': 'https://api.github.com/orgs/bigclownlabs'},
  'payload': {'action': 'created',
   'comment': {'author_association': 'NONE',
    'body': 'Looks good ;) if it is what you mean:\r\n\r\nhttp://en.cppreference.com/w/cpp/error/errno',
    'created_at': '2017-11-16T06:13:36Z',
    'html_url': 'https://github.com/bigclownlabs/bcf-sdk/issues/149#issuecomment-344826427',
    'id': 344826427,
    'issue_url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk/issues/149',
    'updated_at': '2017-11-16T06:13:36Z',
    'url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk/issues/comments/344826427',
    'user': {'avatar_url': 'https://avatars3.githubusercontent.com/u/37391?v=4',
     'events_url': 'https://api.github.com/users/czb/events{/privacy}',
     'followers_url': 'https://api.github.com/users/czb/followers',
     'following_url': 'https://api.github.com/users/czb/following{/other_user}',
     'gists_url': 'https://api.github.com/users/czb/gists{/gist_id}',
     'gravatar_id': '',
     'html_url': 'https://github.com/czb',
     'id': 37391,
     'login': 'czb',
     'organizations_url': 'https://api.github.com/users/czb/orgs',
     'received_events_url': 'https://api.github.com/users/czb/received_events',
     'repos_url': 'https://api.github.com/users/czb/repos',
     'site_admin': False,
     'starred_url': 'https://api.github.com/users/czb/starred{/owner}{/repo}',
     'subscriptions_url': 'https://api.github.com/users/czb/subscriptions',
     'type': 'User',
     'url': 'https://api.github.com/users/czb'}},
   'issue': {'assignee': None,
    'assignees': [],
    'author_association': 'NONE',
    'body': 'On any error `return false;` is returned. On no error, `return true;` is returned.\r\n\r\nI propose to change it such that on no error `0` is returned. On error a positive number is returned.\r\n\r\nAs it is now, it is impossible to know where exactly the function fails...',
    'closed_at': None,
    'comments': 1,
    'comments_url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk/issues/149/comments',
    'created_at': '2017-11-14T08:38:38Z',
    'events_url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk/issues/149/events',
    'html_url': 'https://github.com/bigclownlabs/bcf-sdk/issues/149',
    'id': 273707803,
    'labels': [],
    'labels_url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk/issues/149/labels{/name}',
    'locked': False,
    'milestone': None,
    'number': 149,
    'repository_url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk',
    'state': 'open',
    'title': 'return codes',
    'updated_at': '2017-11-16T06:13:36Z',
    'url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk/issues/149',
    'user': {'avatar_url': 'https://avatars3.githubusercontent.com/u/37391?v=4',
     'events_url': 'https://api.github.com/users/czb/events{/privacy}',
     'followers_url': 'https://api.github.com/users/czb/followers',
     'following_url': 'https://api.github.com/users/czb/following{/other_user}',
     'gists_url': 'https://api.github.com/users/czb/gists{/gist_id}',
     'gravatar_id': '',
     'html_url': 'https://github.com/czb',
     'id': 37391,
     'login': 'czb',
     'organizations_url': 'https://api.github.com/users/czb/orgs',
     'received_events_url': 'https://api.github.com/users/czb/received_events',
     'repos_url': 'https://api.github.com/users/czb/repos',
     'site_admin': False,
     'starred_url': 'https://api.github.com/users/czb/starred{/owner}{/repo}',
     'subscriptions_url': 'https://api.github.com/users/czb/subscriptions',
     'type': 'User',
     'url': 'https://api.github.com/users/czb'}}},
  'public': True,
  'repo': {'id': 78222240,
   'name': 'bigclownlabs/bcf-sdk',
   'url': 'https://api.github.com/repos/bigclownlabs/bcf-sdk'},
  'type': 'IssueCommentEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/11555232?',
   'display_login': 'foochuanwei',
   'gravatar_id': '',
   'id': 11555232,
   'login': 'foochuanwei',
   'url': 'https://api.github.com/users/foochuanwei'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559216',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/5853271?',
   'gravatar_id': '',
   'id': 5853271,
   'login': 'fantasyland',
   'url': 'https://api.github.com/orgs/fantasyland'},
  'payload': {'action': 'started'},
  'public': True,
  'repo': {'id': 9385519,
   'name': 'fantasyland/fantasy-land',
   'url': 'https://api.github.com/repos/fantasyland/fantasy-land'},
  'type': 'WatchEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/4001620?',
   'display_login': 'john00123',
   'gravatar_id': '',
   'id': 4001620,
   'login': 'john00123',
   'url': 'https://api.github.com/users/john00123'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559213',
  'payload': {'before': 'e760fc7c8236c5dd153cc688a8e6b7e09afbe6a2',
   'commits': [{'author': {'email': 'john.torres.hurtado@gmail.com',
      'name': 'John Torres'},
     'distinct': True,
     'message': 'text changes',
     'sha': '388a9cf6c16e8d6864218c0c929c43ebb4fbb53f',
     'url': 'https://api.github.com/repos/john00123/ntnx-CCU-portal/commits/388a9cf6c16e8d6864218c0c929c43ebb4fbb53f'}],
   'distinct_size': 1,
   'head': '388a9cf6c16e8d6864218c0c929c43ebb4fbb53f',
   'push_id': 2128127752,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 109310757,
   'name': 'john00123/ntnx-CCU-portal',
   'url': 'https://api.github.com/repos/john00123/ntnx-CCU-portal'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/22949886?',
   'display_login': 'dlbq',
   'gravatar_id': '',
   'id': 22949886,
   'login': 'dlbq',
   'url': 'https://api.github.com/users/dlbq'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559211',
  'payload': {'description': None,
   'master_branch': 'master',
   'pusher_type': 'user',
   'ref': 'gh-pages',
   'ref_type': 'branch'},
  'public': True,
  'repo': {'id': 110928851,
   'name': 'dlbq/vue-admin-template',
   'url': 'https://api.github.com/repos/dlbq/vue-admin-template'},
  'type': 'CreateEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/5974590?',
   'display_login': 'envunderscoreexplosion',
   'gravatar_id': '',
   'id': 5974590,
   'login': 'envunderscoreexplosion',
   'url': 'https://api.github.com/users/envunderscoreexplosion'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559204',
  'payload': {'before': '4e9310353b4782d07492bf1c409f8078e437fd30',
   'commits': [{'author': {'email': 'matthesont@gmail.com', 'name': 'Matt T'},
     'distinct': True,
     'message': 'aa',
     'sha': '4f7fd29d63114b7056bc4f33dce1c90aa3819b27',
     'url': 'https://api.github.com/repos/envunderscoreexplosion/chickenmaster9000/commits/4f7fd29d63114b7056bc4f33dce1c90aa3819b27'}],
   'distinct_size': 1,
   'head': '4f7fd29d63114b7056bc4f33dce1c90aa3819b27',
   'push_id': 2128127748,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 110921664,
   'name': 'envunderscoreexplosion/chickenmaster9000',
   'url': 'https://api.github.com/repos/envunderscoreexplosion/chickenmaster9000'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/4147978?',
   'display_login': 'rev3rend',
   'gravatar_id': '',
   'id': 4147978,
   'login': 'rev3rend',
   'url': 'https://api.github.com/users/rev3rend'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559201',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/8622233?',
   'gravatar_id': '',
   'id': 8622233,
   'login': 'IDMNYU',
   'url': 'https://api.github.com/orgs/IDMNYU'},
  'payload': {'before': 'a6120670813547061bf889a4fea45ecac64a2c8b',
   'commits': [{'author': {'email': 'rev3rend@gmail.com', 'name': 'rev3rend'},
     'distinct': True,
     'message': 'fixes\n\nfixes!',
     'sha': '7cb51372f4fcfb0cce324c1c094ff785f8ee21b6',
     'url': 'https://api.github.com/repos/IDMNYU/p5.js-func/commits/7cb51372f4fcfb0cce324c1c094ff785f8ee21b6'}],
   'distinct_size': 1,
   'head': '7cb51372f4fcfb0cce324c1c094ff785f8ee21b6',
   'push_id': 2128127747,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 109543668,
   'name': 'IDMNYU/p5.js-func',
   'url': 'https://api.github.com/repos/IDMNYU/p5.js-func'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/6509121?',
   'display_login': 'Snake-Tn',
   'gravatar_id': '',
   'id': 6509121,
   'login': 'Snake-Tn',
   'url': 'https://api.github.com/users/Snake-Tn'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559197',
  'payload': {'before': 'd76d82c6ca9da12def83eb70cbe3a4ed8328f81f',
   'commits': [{'author': {'email': 'kooliahmd@gmail.com',
      'name': 'Ahmed Kooli'},
     'distinct': True,
     'message': 'skip magento install if already installed',
     'sha': '3809c41c6fa93c4fe5b890ba4662bc165d6e3ba2',
     'url': 'https://api.github.com/repos/Snake-Tn/magento2Docker/commits/3809c41c6fa93c4fe5b890ba4662bc165d6e3ba2'}],
   'distinct_size': 1,
   'head': '3809c41c6fa93c4fe5b890ba4662bc165d6e3ba2',
   'push_id': 2128127745,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 90787090,
   'name': 'Snake-Tn/magento2Docker',
   'url': 'https://api.github.com/repos/Snake-Tn/magento2Docker'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/1332366?',
   'display_login': 'rememberlenny',
   'gravatar_id': '',
   'id': 1332366,
   'login': 'rememberlenny',
   'url': 'https://api.github.com/users/rememberlenny'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559196',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/6233994?',
   'gravatar_id': '',
   'id': 6233994,
   'login': '18F',
   'url': 'https://api.github.com/orgs/18F'},
  'payload': {'before': '5cd6e76ebf5fe44eaa39cf196f66780fe11872f8',
   'commits': [{'author': {'email': 'rememberlenny@gmail.com',
      'name': 'Leonard Bogdonoff'},
     'distinct': True,
     'message': 'Fix vertical rhythm around nested lists',
     'sha': '47d19bd084c7e37d4217af58252ee18e79ccbeec',
     'url': 'https://api.github.com/repos/18F/omb-eregs/commits/47d19bd084c7e37d4217af58252ee18e79ccbeec'}],
   'distinct_size': 1,
   'head': '47d19bd084c7e37d4217af58252ee18e79ccbeec',
   'push_id': 2128127744,
   'ref': 'refs/heads/lkb-styling',
   'size': 1},
  'public': True,
  'repo': {'id': 78458357,
   'name': '18F/omb-eregs',
   'url': 'https://api.github.com/repos/18F/omb-eregs'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/8517910?',
   'display_login': 'LombiqBot',
   'gravatar_id': '',
   'id': 8517910,
   'login': 'LombiqBot',
   'url': 'https://api.github.com/users/LombiqBot'},
  'created_at': '2017-11-16T06:13:36Z',
  'id': '6862559193',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/8158177?',
   'gravatar_id': '',
   'id': 8158177,
   'login': 'Lombiq',
   'url': 'https://api.github.com/orgs/Lombiq'},
  'payload': {'before': 'c610ec38acbac2892a0e295983531d837a39c6fc',
   'commits': [],
   'distinct_size': 0,
   'head': 'c610ec38acbac2892a0e295983531d837a39c6fc',
   'push_id': 2128127741,
   'ref': 'refs/heads/Orchard-1.9',
   'size': 0},
  'public': True,
  'repo': {'id': 46629356,
   'name': 'Lombiq/Orchard-Scripting-Extensions-PHP',
   'url': 'https://api.github.com/repos/Lombiq/Orchard-Scripting-Extensions-PHP'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/8517910?',
   'display_login': 'LombiqBot',
   'gravatar_id': '',
   'id': 8517910,
   'login': 'LombiqBot',
   'url': 'https://api.github.com/users/LombiqBot'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559188',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/8158177?',
   'gravatar_id': '',
   'id': 8158177,
   'login': 'Lombiq',
   'url': 'https://api.github.com/orgs/Lombiq'},
  'payload': {'before': 'd16368563a853970599eaf38889732309788cdd1',
   'commits': [],
   'distinct_size': 0,
   'head': 'd16368563a853970599eaf38889732309788cdd1',
   'push_id': 2128127740,
   'ref': 'refs/heads/issue/BTLR-63',
   'size': 0},
  'public': True,
  'repo': {'id': 46592886,
   'name': 'Lombiq/Associativy-Core',
   'url': 'https://api.github.com/repos/Lombiq/Associativy-Core'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/26447601?',
   'display_login': 'OPSTestPPE',
   'gravatar_id': '',
   'id': 26447601,
   'login': 'OPSTestPPE',
   'url': 'https://api.github.com/users/OPSTestPPE'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559184',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/24789825?',
   'gravatar_id': '',
   'id': 24789825,
   'login': 'OPS-E2E-PPE',
   'url': 'https://api.github.com/orgs/OPS-E2E-PPE'},
  'payload': {'before': '555b87a7fd5a1a3aa93ee44d74990fe086fa4775',
   'commits': [{'author': {'email': 'opse2etestingppe@outlook.com',
      'name': 'OPSTestPPE'},
     'distinct': True,
     'message': 'MasterRedirect: source_path and redirect_url are null Thu, 16 Nov 2017 06:12:47 GMT',
     'sha': 'dbb97341a7da748f951480cddcd9d21a6df81b46',
     'url': 'https://api.github.com/repos/OPS-E2E-PPE/E2E_DocsBranch_Dynamic/commits/dbb97341a7da748f951480cddcd9d21a6df81b46'}],
   'distinct_size': 1,
   'head': 'dbb97341a7da748f951480cddcd9d21a6df81b46',
   'push_id': 2128127736,
   'ref': 'refs/heads/redirect-e2e',
   'size': 1},
  'public': True,
  'repo': {'id': 81908100,
   'name': 'OPS-E2E-PPE/E2E_DocsBranch_Dynamic',
   'url': 'https://api.github.com/repos/OPS-E2E-PPE/E2E_DocsBranch_Dynamic'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/11935196?',
   'display_login': 'SkyTank',
   'gravatar_id': '',
   'id': 11935196,
   'login': 'SkyTank',
   'url': 'https://api.github.com/users/SkyTank'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559183',
  'payload': {'description': None,
   'master_branch': 'master',
   'pusher_type': 'user',
   'ref': None,
   'ref_type': 'repository'},
  'public': True,
  'repo': {'id': 110931037,
   'name': 'SkyTank/testAssembly',
   'url': 'https://api.github.com/repos/SkyTank/testAssembly'},
  'type': 'CreateEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/6948067?',
   'display_login': 'pranavlathigara',
   'gravatar_id': '',
   'id': 6948067,
   'login': 'pranavlathigara',
   'url': 'https://api.github.com/users/pranavlathigara'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559182',
  'org': {'avatar_url': 'https://avatars.githubusercontent.com/u/1342004?',
   'gravatar_id': '',
   'id': 1342004,
   'login': 'google',
   'url': 'https://api.github.com/orgs/google'},
  'payload': {'action': 'started'},
  'public': True,
  'repo': {'id': 110616531,
   'name': 'google/swift',
   'url': 'https://api.github.com/repos/google/swift'},
  'type': 'WatchEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/33278815?',
   'display_login': 'pangnima',
   'gravatar_id': '',
   'id': 33278815,
   'login': 'pangnima',
   'url': 'https://api.github.com/users/pangnima'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559179',
  'payload': {'before': '39b95fcdcfef6675b2e23ff5708db41da6da139d',
   'commits': [{'author': {'email': 'pangnima@gmail.com', 'name': 'pangnima'},
     'distinct': True,
     'message': 'test3',
     'sha': '706f0345d95e1db7893bc60d0bf43a652f2cc1c9',
     'url': 'https://api.github.com/repos/sharkroo/miraen/commits/706f0345d95e1db7893bc60d0bf43a652f2cc1c9'}],
   'distinct_size': 1,
   'head': '706f0345d95e1db7893bc60d0bf43a652f2cc1c9',
   'push_id': 2128127735,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 109197762,
   'name': 'sharkroo/miraen',
   'url': 'https://api.github.com/repos/sharkroo/miraen'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/21096693?',
   'display_login': 'kikebe',
   'gravatar_id': '',
   'id': 21096693,
   'login': 'kikebe',
   'url': 'https://api.github.com/users/kikebe'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559177',
  'payload': {'description': '移行用テストリポジトリです',
   'master_branch': 'master',
   'pusher_type': 'user',
   'ref': None,
   'ref_type': 'repository'},
  'public': True,
  'repo': {'id': 110931036,
   'name': 'kikebe/test-repository',
   'url': 'https://api.github.com/repos/kikebe/test-repository'},
  'type': 'CreateEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/32923229?',
   'display_login': 'AbrahamJay',
   'gravatar_id': '',
   'id': 32923229,
   'login': 'AbrahamJay',
   'url': 'https://api.github.com/users/AbrahamJay'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559169',
  'payload': {'action': 'started'},
  'public': True,
  'repo': {'id': 88046745,
   'name': 'ilyagru/Space-Snake',
   'url': 'https://api.github.com/repos/ilyagru/Space-Snake'},
  'type': 'WatchEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/1508308?',
   'display_login': 'chebykinn',
   'gravatar_id': '',
   'id': 1508308,
   'login': 'chebykinn',
   'url': 'https://api.github.com/users/chebykinn'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559165',
  'payload': {'before': 'dabbb9124cfd74255bc4042fe30a29d304b6332c',
   'commits': [{'author': {'email': 'ivan@chebykin.org',
      'name': 'Ivan Chebykin'},
     'distinct': True,
     'message': 'sig_proc_course: updated report',
     'sha': 'b6478f126892c562318a4141e571c4f1a162c47e',
     'url': 'https://api.github.com/repos/chebykinn/university/commits/b6478f126892c562318a4141e571c4f1a162c47e'}],
   'distinct_size': 1,
   'head': 'b6478f126892c562318a4141e571c4f1a162c47e',
   'push_id': 2128127730,
   'ref': 'refs/heads/sig_proc_course',
   'size': 1},
  'public': True,
  'repo': {'id': 70061560,
   'name': 'chebykinn/university',
   'url': 'https://api.github.com/repos/chebykinn/university'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/7260463?',
   'display_login': 'sohomghosh',
   'gravatar_id': '',
   'id': 7260463,
   'login': 'sohomghosh',
   'url': 'https://api.github.com/users/sohomghosh'},
  'created_at': '2017-11-16T06:13:35Z',
  'id': '6862559162',
  'payload': {'before': '686752bbc49bfd33986ac806dc5155a3a1a53bb8',
   'commits': [{'author': {'email': 'sohom1ghosh@gmail.com',
      'name': 'Sohom Ghosh'},
     'distinct': True,
     'message': 'Create fib.o',
     'sha': '89531254677feb2963f36fc59b9129988ca3b9dc',
     'url': 'https://api.github.com/repos/sohomghosh/Python_Machine-Learning_Codes/commits/89531254677feb2963f36fc59b9129988ca3b9dc'}],
   'distinct_size': 1,
   'head': '89531254677feb2963f36fc59b9129988ca3b9dc',
   'push_id': 2128127729,
   'ref': 'refs/heads/master',
   'size': 1},
  'public': True,
  'repo': {'id': 51534569,
   'name': 'sohomghosh/Python_Machine-Learning_Codes',
   'url': 'https://api.github.com/repos/sohomghosh/Python_Machine-Learning_Codes'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/15375665?',
   'display_login': 'reksarw',
   'gravatar_id': '',
   'id': 15375665,
   'login': 'reksarw',
   'url': 'https://api.github.com/users/reksarw'},
  'created_at': '2017-11-16T06:13:34Z',
  'id': '6862559160',
  'payload': {'description': 'Chuck Norris Quotes, API from https://api.chucknorris.io/',
   'master_branch': 'master',
   'pusher_type': 'user',
   'ref': None,
   'ref_type': 'repository'},
  'public': True,
  'repo': {'id': 110931035,
   'name': 'reksarw/ChuckNorris-Quotes',
   'url': 'https://api.github.com/repos/reksarw/ChuckNorris-Quotes'},
  'type': 'CreateEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/14323651?',
   'display_login': 'castielLi',
   'gravatar_id': '',
   'id': 14323651,
   'login': 'castielLi',
   'url': 'https://api.github.com/users/castielLi'},
  'created_at': '2017-11-16T06:13:34Z',
  'id': '6862559157',
  'payload': {'before': '7e1d205486742eeceddad1751588248f05056535',
   'commits': [{'author': {'email': '534634672@qq.com',
      'name': 'HuangHaoDong'},
     'distinct': False,
     'message': 'fix输入框',
     'sha': 'bab4d4dbd95134eded15b9c7efc7e9d55a4776b6',
     'url': 'https://api.github.com/repos/castielLi/IM/commits/bab4d4dbd95134eded15b9c7efc7e9d55a4776b6'},
    {'author': {'email': '534634672@qq.com', 'name': 'HuangHaoDong'},
     'distinct': False,
     'message': "Merge branch 'develope' of https://github.com/castielLi/IM into huanghaodong-develope",
     'sha': '83a06a072a64d29e604432b8e44d6e098e1a39b8',
     'url': 'https://api.github.com/repos/castielLi/IM/commits/83a06a072a64d29e604432b8e44d6e098e1a39b8'},
    {'author': {'email': '534634672@qq.com', 'name': 'HuangHaoDong'},
     'distinct': False,
     'message': 'update返回',
     'sha': '17d1e34fbcfaf9281041825f29f92720ccc4874c',
     'url': 'https://api.github.com/repos/castielLi/IM/commits/17d1e34fbcfaf9281041825f29f92720ccc4874c'},
    {'author': {'email': '534634672@qq.com', 'name': 'HuangHaoDong'},
     'distinct': False,
     'message': 'fix',
     'sha': 'bc93f15696aa85d609898ec48c22ace7a8aaf9bc',
     'url': 'https://api.github.com/repos/castielLi/IM/commits/bc93f15696aa85d609898ec48c22ace7a8aaf9bc'},
    {'author': {'email': '252182398@qq.com', 'name': 'castiel'},
     'distinct': True,
     'message': "Merge branch 'develope' into lizongjun",
     'sha': 'b4cea11e5a23326b758c5c7cae33652c132b0f1c',
     'url': 'https://api.github.com/repos/castielLi/IM/commits/b4cea11e5a23326b758c5c7cae33652c132b0f1c'}],
   'distinct_size': 1,
   'head': 'b4cea11e5a23326b758c5c7cae33652c132b0f1c',
   'push_id': 2128127727,
   'ref': 'refs/heads/lizongjun',
   'size': 5},
  'public': True,
  'repo': {'id': 103912077,
   'name': 'castielLi/IM',
   'url': 'https://api.github.com/repos/castielLi/IM'},
  'type': 'PushEvent'},
 {'actor': {'avatar_url': 'https://avatars.githubusercontent.com/u/24440052?',
   'display_login': 'puuurm',
   'gravatar_id': '',
   'id': 24440052,
   'login': 'puuurm',
   'url': 'https://api.github.com/users/puuurm'},
  'created_at': '2017-11-16T06:13:34Z',
  'id': '6862559156',
  'payload': {'before': 'c03fac999d1f7e4be5f3f0588e49933cdccf59fd',
   'commits': [{'author': {'email': 'puuurm@naver.com',
      'name': 'yang hee jung'},
     'distinct': True,
     'message': 'Modify className property',
     'sha': 'd33b0c2bacf30787b7b0b579f762cf015e5bd27a',
     'url': 'https://api.github.com/repos/puuurm/swift-vendingmachine/commits/d33b0c2bacf30787b7b0b579f762cf015e5bd27a'}],
   'distinct_size': 1,
   'head': 'd33b0c2bacf30787b7b0b579f762cf015e5bd27a',
   'push_id': 2128127726,
   'ref': 'refs/heads/vendingmachine-step2',
   'size': 1},
  'public': True,
  'repo': {'id': 110520175,
   'name': 'puuurm/swift-vendingmachine',
   'url': 'https://api.github.com/repos/puuurm/swift-vendingmachine'},
  'type': 'PushEvent'}]

In case the JSON decoding fails, r.json() raises an exception. For example, if the response gets a 204(No Content) or the response contains invalid JSON, attempting r.json() raises

ValueError: No JSON object could be decoded

It should also be noted that the success of the call to r.json() does not indicate the success of the response. Some servers may return a JSON object in a failed response. Such JSON will be decoded and returned. To check that a request is successful use r.raise_for_status() or check r.status_code is what you expect.

Raw response content


In [24]:
# get request
r = requests.get('https://api.github.com/events',stream=True)
r.raw.read(10)


Out[24]:
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03'

In general however you should use a pattern like this to save what is being streamed to file.

with open(filename,'wb') as fd:
    for chunk in r.iter_content(chunk_size=128):
        fd.write(chunk)

Using Response.iter_content will handle a lot of what you would otherwise have to handle when using Response.raw directly. When streaming a download, the above is the preferred and recommended way to retrieve the content. Note that chunk_size can be freely adjusted to a number that may better fit your use cases.

Custom Headers

If you'd like to add HTTP headers to a request, simply pass in a dict to the headers parameter.

For example we did n't specify the user-agent in the previous example


In [25]:
# get request
url = 'https://api.github.com/events'
headers = {'user-agent':'app-request'}
r = requests.get(url,headers)
r.headers


Out[25]:
{'Date': 'Thu, 16 Nov 2017 06:27:02 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Server': 'GitHub.com', 'Status': '200 OK', 'X-RateLimit-Limit': '60', 'X-RateLimit-Remaining': '48', 'X-RateLimit-Reset': '1510815579', 'Cache-Control': 'public, max-age=60, s-maxage=60', 'Vary': 'Accept, Accept-Encoding', 'ETag': 'W/"5f57fd0583f6d5ce8b01632ee5299e1a"', 'Last-Modified': 'Thu, 16 Nov 2017 06:27:02 GMT', 'X-Poll-Interval': '60', 'X-GitHub-Media-Type': 'github.v3; format=json', 'Link': '<https://api.github.com/events?user-agent=app-request&page=2>; rel="next", <https://api.github.com/events?user-agent=app-request&page=10>; rel="last"', 'Access-Control-Expose-Headers': 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval', 'Access-Control-Allow-Origin': '*', 'Content-Security-Policy': "default-src 'none'", 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'deny', 'X-XSS-Protection': '1; mode=block', 'X-Runtime-rack': '0.099809', 'Content-Encoding': 'gzip', 'X-GitHub-Request-Id': 'C334:2B8F:65C844:778E3E:5A0D2FB5'}

Note that the custom headers are given less precedence than more specific sources of information.

  • Authorization headers set with headers= will be overridden if credentials are specified in .netrc which will be overridden by the auth= parameter.
  • Authorization headers will be removed if you get redirected off-host.
  • Proxy-Authorization headers will be overridden by proxy credentials provided in the URL
  • Content-Length headers will be overridden when we can determine the length of the content.

Advanced POST requests

Typically, you want to send some form-encoded data much like an HTML form. To do this, simply pass a dictionary to the data argument. You dictionary of data will automatically be form-encoded when the request is made.


In [27]:
# using form-encoded data with a dictionary
payload = {'name':'john','age':12}
r = requests.post('https://httpbin.org/post',data=payload)
print(r.text)


{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "age": "12", 
    "name": "john"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "16", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.14.2"
  }, 
  "json": null, 
  "origin": "175.136.245.133", 
  "url": "https://httpbin.org/post"
}

You can also pass a list of tuples to the data argument. This is particularly useful when the form has multiple elements that use the same key:


In [28]:
# using form-encoded data with a tuple
payload = (('name','john'),('age',12))
r = requests.post('https://httpbin.org/post',data=payload)
print(r.text)


{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "age": "12", 
    "name": "john"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "16", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.14.2"
  }, 
  "json": null, 
  "origin": "175.136.245.133", 
  "url": "https://httpbin.org/post"
}


In [30]:
# using json
import jsonpayload = {'name':'john','age':12}
r = requests.post('https://httpbin.org/post',data=payload)
print(r.text)
payload = {'name':'john','age':12}
r = requests.post('https://httpbin.org/post',data=json.dumps(payload))
print(r.text)


{
  "args": {}, 
  "data": "{\"name\": \"john\", \"age\": 12}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "27", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.14.2"
  }, 
  "json": {
    "age": 12, 
    "name": "john"
  }, 
  "origin": "175.136.245.133", 
  "url": "https://httpbin.org/post"
}


In [31]:
payload = {'name':'john','age':12}
r = requests.post('https://httpbin.org/post',json=payload)
print(r.text)


{
  "args": {}, 
  "data": "{\"name\": \"john\", \"age\": 12}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "27", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.14.2"
  }, 
  "json": {
    "age": 12, 
    "name": "john"
  }, 
  "origin": "175.136.245.133", 
  "url": "https://httpbin.org/post"
}

Post a Multipart - Encoded File


In [32]:
url = 'http://httpbin.org/post'
files = {'file':open('test.xls','rb')}

r = requests.post(url,files=files)
r.text


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-32-ec8a334a3edf> in <module>()
      1 url = 'http://httpbin.org/post'
----> 2 files = {'file':open('test.xls','rb')}
      3 
      4 r = requests.post(url,files=files)
      5 r.text

FileNotFoundError: [Errno 2] No such file or directory: 'test.xls'

In [33]:
# set filename, content-type and headers explicitly
url = 'http://httpbin.org/post'
files = {'file':('report.xls',open(),'application/vnd.ms-excel',{'Expires':'0'})}
r = requests.post(url,files=files)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-33-3e3f1e048ac8> in <module>()
      1 # set filename, content-type and headers explicitly
      2 url = 'http://httpbin.org/post'
----> 3 files = {'file':('report.xls',open(),'application/vnd.ms-excel',{'Expires':'0'})}
      4 r = requests.post(url,files=files)

TypeError: Required argument 'file' (pos 1) not found

In the event you are posting a very large file as multipart/form-data request you may want to stream the request. By default requests does not support this but there is a separate package which does -requests-toolbelt.

Post Multiple Multipart-Encoded Files

You can send multiple files in one request. For example, suppose you want to upload image files to an HTML form with a multiple file field 'images':


In [55]:
url = 'http://httpbin.org/post'
multiple_files = [
    ('images',('foo.png',open('foo.png','rb'),'image/png')),
    ('images',('bar.png',open('foo.png','rb'),'image/png'))
]
r = requests.post(url,file=multiple_files)
r.text


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-55-18ae54faecce> in <module>()
      1 url = 'http://httpbin.org/post'
      2 multiple_files = [
----> 3     ('images',('foo.png',open('foo.png','rb'),'image/png')),
      4     ('images',('bar.png',open('foo.png','rb'),'image/png'))
      5 ]

FileNotFoundError: [Errno 2] No such file or directory: 'foo.png'

Response Status Codes

We can check the response status code:


In [35]:
r = requests.get('http://httpbin.org/get')
r.status_code


Out[35]:
200

In [36]:
# built in status code objects
r.status_code == requests.codes.ok


Out[36]:
True

In [37]:
# bad request, raise exception
bad_r = requests.get('http://httpbin.org/status/404')
bad_r.status_code


Out[37]:
404

In [38]:
bad_r.raise_for_status()


---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-38-cdf6910f7d4c> in <module>()
----> 1 bad_r.raise_for_status()

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/models.py in raise_for_status(self)
    926 
    927         if http_error_msg:
--> 928             raise HTTPError(http_error_msg, response=self)
    929 
    930     def close(self):

HTTPError: 404 Client Error: NOT FOUND for url: http://httpbin.org/status/404

In [39]:
r.raise_for_status()

Response Headers


In [40]:
# get the headers
r.headers


Out[40]:
{'Connection': 'keep-alive', 'Server': 'meinheld/0.6.1', 'Date': 'Thu, 16 Nov 2017 06:48:24 GMT', 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Credentials': 'true', 'X-Powered-By': 'Flask', 'X-Processed-Time': '0.000694036483765', 'Content-Length': '268', 'Via': '1.1 vegur'}

In [41]:
# access headers
r.headers['Content-Type']


Out[41]:
'application/json'

In [42]:
# access headers using get
r.headers.get('content-type')


Out[42]:
'application/json'

Cookies


In [44]:
url = 'http://example.com/some/cookie/setting/url'
r = requests.get(url)
r.cookies['example-cookie-name']


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-44-3b698e65f0ea> in <module>()
      1 url = 'http://example.com/some/cookie/setting/url'
      2 r = requests.get(url)
----> 3 r.cookies['example-cookie-name']

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/cookies.py in __getitem__(self, name)
    325         .. warning:: operation is O(n), not O(1).
    326         """
--> 327         return self._find_no_duplicates(name)
    328 
    329     def __setitem__(self, name, value):

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/cookies.py in _find_no_duplicates(self, name, domain, path)
    396         if toReturn:
    397             return toReturn
--> 398         raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
    399 
    400     def __getstate__(self):

KeyError: "name='example-cookie-name', domain=None, path=None"

In [45]:
# send cookies
url = 'http://httpbin.org/cookies'
cookies = dict(cookies_are='working')
r = requests.get(url,cookies=cookies)
r.text


Out[45]:
'{\n  "cookies": {\n    "cookies_are": "working"\n  }\n}\n'

Cookies are returned in a RequestsCookieJar, which acts like a dict but also offers a more complete interface, suitable for use over multiple domains or paths.


In [46]:
jar = requests.cookies.RequestsCookieJar()
jar.set('tasty-cookie','yum',domain='httpbin.org',path='/cookies')
url = 'http://httpbin.org/cookies'
r = requests.get(url,cookies=jar)
r.text


Out[46]:
'{\n  "cookies": {\n    "tasty-cookie": "yum"\n  }\n}\n'

In [47]:
r.cookies


Out[47]:
<RequestsCookieJar[]>

Redirection and History

By default Requests will perform location redirection for all verbs except HEAD.

We can use the history property of the Response object to track redirection.

The Response.history list contains the Response objects that were created in order to complete the request. The list is sorted from the oldest to the most recent response.


In [48]:
r = requests.get('http://github.com')
r.url


Out[48]:
'https://github.com/'

In [49]:
r.status_code


Out[49]:
200

In [50]:
r.history


Out[50]:
[<Response [301]>]

If you are using GET,OPTIONS,POST,PUT,PATCH or DELETE you can disable redirection handling with the allow_redirects parameter.


In [51]:
r = requests.get('http://github.com',allow_redirects=False)
r.status_code


Out[51]:
301

In [52]:
r.history


Out[52]:
[]

Timeouts

Most requests to externals servers should have a timeout attached, in case the server is not responding in a timely manner. By default, requests do not time out unless a timeout value is set explicitly. Without a timeout, your code may hang for minutes or more.

The connect timeout is the number of seconds Requests will wait for your client to establish a connection to a remote machine call on the socket. It is a good practice to set connect timeouts to slightly larger than a multiple of 3, which is the default TCP packet retransmission window.

Once your client has connected to the server and sent the HTTP request, the read timeout is the number of the seconds the client will wait for the server to send a response. Specifically its the number of seconds that the client will wait between bytes sent from a server. In 99.9% of cases, this is the time before the server sends the first byte).


In [53]:
requests.get('http://github.com',timeout=0.001)


---------------------------------------------------------------------------
timeout                                   Traceback (most recent call last)
/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connection.py in _new_conn(self)
    140             conn = connection.create_connection(
--> 141                 (self.host, self.port), self.timeout, **extra_kw)
    142 

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     82     if err is not None:
---> 83         raise err
     84 

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     72                 sock.bind(source_address)
---> 73             sock.connect(sa)
     74             return sock

timeout: timed out

During handling of the above exception, another exception occurred:

ConnectTimeoutError                       Traceback (most recent call last)
/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    599                                                   body=body, headers=headers,
--> 600                                                   chunked=chunked)
    601 

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    355         else:
--> 356             conn.request(method, url, **httplib_request_kw)
    357 

/Users/cnc/anaconda/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1238         """Send a complete request to the server."""
-> 1239         self._send_request(method, url, body, headers, encode_chunked)
   1240 

/Users/cnc/anaconda/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1284             body = _encode(body, 'body')
-> 1285         self.endheaders(body, encode_chunked=encode_chunked)
   1286 

/Users/cnc/anaconda/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked)
   1233             raise CannotSendHeader()
-> 1234         self._send_output(message_body, encode_chunked=encode_chunked)
   1235 

/Users/cnc/anaconda/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked)
   1025         del self._buffer[:]
-> 1026         self.send(msg)
   1027 

/Users/cnc/anaconda/lib/python3.6/http/client.py in send(self, data)
    963             if self.auto_open:
--> 964                 self.connect()
    965             else:

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connection.py in connect(self)
    165     def connect(self):
--> 166         conn = self._new_conn()
    167         self._prepare_conn(conn)

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connection.py in _new_conn(self)
    145                 self, "Connection to %s timed out. (connect timeout=%s)" %
--> 146                 (self.host, self.timeout))
    147 

ConnectTimeoutError: (<requests.packages.urllib3.connection.HTTPConnection object at 0x1094a6e80>, 'Connection to github.com timed out. (connect timeout=0.001)')

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
/Users/cnc/anaconda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    437                     retries=self.max_retries,
--> 438                     timeout=timeout
    439                 )

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    648             retries = retries.increment(method, url, error=e, _pool=self,
--> 649                                         _stacktrace=sys.exc_info()[2])
    650             retries.sleep()

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    387         if new_retry.is_exhausted():
--> 388             raise MaxRetryError(_pool, url, error or ResponseError(cause))
    389 

MaxRetryError: HTTPConnectionPool(host='github.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x1094a6e80>, 'Connection to github.com timed out. (connect timeout=0.001)'))

During handling of the above exception, another exception occurred:

ConnectTimeout                            Traceback (most recent call last)
<ipython-input-53-ef704087d7e7> in <module>()
----> 1 requests.get('http://github.com',timeout=0.001)

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/api.py in get(url, params, **kwargs)
     70 
     71     kwargs.setdefault('allow_redirects', True)
---> 72     return request('get', url, params=params, **kwargs)
     73 
     74 

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/api.py in request(method, url, **kwargs)
     56     # cases, and look like a memory leak in others.
     57     with sessions.Session() as session:
---> 58         return session.request(method=method, url=url, **kwargs)
     59 
     60 

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    516         }
    517         send_kwargs.update(settings)
--> 518         resp = self.send(prep, **send_kwargs)
    519 
    520         return resp

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
    637 
    638         # Send the request
--> 639         r = adapter.send(request, **kwargs)
    640 
    641         # Total elapsed time of the request (approximately)

/Users/cnc/anaconda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    492                 # TODO: Remove this in 3.0.0: see #2811
    493                 if not isinstance(e.reason, NewConnectionError):
--> 494                     raise ConnectTimeout(e, request=request)
    495 
    496             if isinstance(e.reason, ResponseError):

ConnectTimeout: HTTPConnectionPool(host='github.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x1094a6e80>, 'Connection to github.com timed out. (connect timeout=0.001)'))

Note: timeout is not a time limit on the entire response download, rather an exception is raised when server has not issued a response for timeout seconds.If no timeout is specified explicitly requests do not timeout.


In [64]:
# single value timeout
# good for both 'connect' and 'read' timeouts
r = requests.get('https://github.com',timeout=5)

In [65]:
# separate value for 'connect' and 'readout' timeouts
r = requests.get('https://github.com',timeout=(3.05,27))

If the remote server is very slow, you can tell Requests to wait forever for a response, by passing None as a timeout value and then retrieving a cup of coffee.


In [66]:
r = requests.get('https://github.com',timeout=None)

Errors and Exception

In the event of a network problem, Requests will raise a ConnectionError exception

Response.raise_for_status() will raise an HTTPError if the HTTP request returned an unsuccessful status code.

If a request times out, a Timeout exception is raises.

If a request exceeds the configured the number of maximum redirections a TooManyRedirects exception is raised.

All exceptions that Requests explicitly raises inherit from requests.exceptions.RequestException

Event Hooks

Requests has a hook system that you can use to manipulate portions of the request process or signal event handling.

Available Hooks:

  • response - response generated from a request

You can assign a hook function on a per-request basis by passing a {hook_name:callback_function} dictionary to the hooks request parameter.


In [57]:
# call back function - print url function
def print_url(r, *args, **kwargs):
    print(r.url)
    
requests.get('http://httpbin.org',hooks={'response':print_url})


http://httpbin.org/
Out[57]:
<Response [200]>

In [58]:
# second callback function
def record_hook(r,*args,**kwargs):
    r.hook_called = True
    return r

In [59]:
# add multiple hooks to a single request
requests.get('http://httpbin.org',hooks={'response':[print_url,record_hook]})


http://httpbin.org/
Out[59]:
<Response [200]>

In [61]:
r = requests.get('http://httpbin.org',hooks={'response':[print_url,record_hook]})
r.hook_called


http://httpbin.org/
Out[61]:
True

Proxies

If you need to use a proxy, you can configure individual requests with the proxies argument to any request method:


In [63]:
# proxies = {'http':'http://10.10.1.10:3128','https':'http://10.10.1.10:1080'}
# requests.get('http://example.org',proxies = proxies)

To use HTTP Basic Auth with your proxy use the http://user:password@host/syntax

To give a proxy for a specific scheme and host use the scheme://hostname form for the key. This will match for any request to the given scheme and hostname.

proxies={'http://10.20.1.18':'http://10.20.1.292:5342'}

Chunk Encoded Requests

Requests also supports Chunked transfer encoding for outgoing and incoming requests. To send a chunk-encoded request, simply provide a generator (or any iterator without a length) for your body.

def gen():
    yield 'hi'
    yield 'there'
requests.post('http://some.url/chunked',data=gen())

For chunked encoded repsonses its best to iterate over the data using Response.iter_content(). In an ideal situation you'll have set stream=True on the request, in which case you can iterate chunk-by-chunk by calling iter_content with a chunk_size parameter of None. If you want to set a maximum size of the chunk, you can set a chunk_size parameter to any integer.

Streaming Requests

With Response.iter_lines() you can easily iterate over streaming APIs such as Twitter Streaming API. Simply set to Stream to True and iterate over the response with iter_lines:


In [68]:
import json
import requests

r = requests.get('http://httpbin.org/stream/5',stream=True)

for line in r.iter_lines():
    # filter out keep-alive new lines
    if line:
        decoded_line = line.decode('utf-8')
        print(json.loads(decoded_line))


{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 0, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 1, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 2, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 3, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 4, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}

When using decode_unicode=True with Response.iter_lines() or Response.iter_content(), provide a fallback encoding in the event the server does n't provide one:


In [69]:
r = requests.get('http://httpbin.org/stream/5', stream=True)

if r.encoding is None:
    r.encoding = 'utf-8'
    
for line in r.iter_lines(decode_unicode=True):
    if line:
        print(json.loads(line))


{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 0, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 1, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 2, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 3, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}
{'headers': {'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Accept': '*/*', 'User-Agent': 'python-requests/2.14.2', 'Host': 'httpbin.org'}, 'id': 4, 'origin': '175.136.245.133', 'args': {}, 'url': 'http://httpbin.org/stream/5'}

Session Objects

The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance and will use urllib3's connection pooling. So if you are making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase.


In [70]:
s = requests.Session()
s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
r = s.get('http://httpbin.org/cookies')

print(r.text)


{
  "cookies": {
    "sessioncookie": "123456789"
  }
}

Sessions can also be used to provide default data to the request methods. This is done by providing data to the properties on a Session object:


In [71]:
s = requests.Session()
s.auth = ('user','pass')
s.headers.update({'x-test':'true'})

# both x-test and x-test are send
s.get('http://httpbin.org/headers', headers={'x-test-2':'true'})


Out[71]:
<Response [200]>

Any dictionaries you pass to a request method will be merged with the session-level values that are set. The method level parameters override the session parameters.

Note however that method level parameteres will not be persisted across requests even if using a session. The following example will only send the cooking with the first request but not the second:


In [72]:
s = requests.Session()

r = s.get('http://httpbin.org/cookies',cookies={'from-my':'browser'})
print(r.text)


{
  "cookies": {
    "from-my": "browser"
  }
}


In [73]:
r = s.get('http://httpbin.org/cookies')
print(r.text)


{
  "cookies": {}
}

Sessions can also be used as context managers:

with requests.Session() as s:
    s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')

This will make sure the session is closed as soon as the with block is exited, even if unhandled exceptions occurred.


In [ ]: