File tree Expand file tree Collapse file tree 2 files changed +12
-14
lines changed
Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Original file line number Diff line number Diff line change 44import subprocess
55
66setup (name = "stitchclient" ,
7- version = "0.4.1 " ,
7+ version = "0.4.2 " ,
88 description = "A Stitch API client for Python" ,
99 author = "Stitch" ,
10101111 url = "https://github.com/stitchdata/python-stitch-client" ,
1212 classifiers = ['Programming Language :: Python :: 3 :: Only' ],
1313 packages = find_packages (),
14- install_requires = ["python-dateutil" , "msgpack-python" ])
14+ install_requires = [
15+ "python-dateutil" ,
16+ "msgpack-python" ,
17+ "request==2.12.4" ,
18+ ])
Original file line number Diff line number Diff line change 33import logging
44import collections
55
6- import urllib . request
6+ import requests
77
88from collections import deque
99from io import StringIO
@@ -122,25 +122,19 @@ def _serialize_entries(self, entries):
122122 def _stitch_request (self , body ):
123123 headers = {'Authorization' : 'Bearer {}' .format (self .token ),
124124 'Content-Type' : 'application/transit+json' }
125- req = urllib .request .Request (self .stitch_url , body .encode ("utf8" ), headers )
126-
127- try :
128- with urllib .request .urlopen (req ) as response :
129- return response
130- except urllib .error .HTTPError as e :
131- logger .error (e .read ())
132- raise e
125+ return requests .post (self .stitch_url , headers = headers , data = body )
133126
134127 def _send_batch (self , batch ):
135128 logger .debug ("Sending batch of %s entries" , len (batch ))
136129 body = self ._serialize_entries (batch )
137130 response = self ._stitch_request (body )
138- if response .status < 300 :
131+
132+ if response .status_code < 300 :
139133 if self .callback_function is not None :
140134 self .callback_function ([x .callback_arg for x in batch ])
141135 else :
142- raise RuntimeError ("Error sending data to the Stitch API, with response status code {}" . format ( response . status ))
143-
136+ raise RuntimeError ("Error sending data to the Stitch API. {0.status_code} - {0.content}"
137+ . format ( response ))
144138
145139 def flush (self ):
146140 while True :
You can’t perform that action at this time.
0 commit comments