Skip to content

Commit

Permalink
Update lib.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yuantailing committed Apr 22, 2019
1 parent 06e6d58 commit 67025e1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tunet/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def get(url, data, callback, dataType):
data['callback'] = 'callback'
_data = parse.urlencode(data)
req = request.Request(url + '?' + _data if _data else url)
res = request.urlopen(req, timeout=5) # TODO: hardcode
assert 200 == res.getcode()
res = request.urlopen(req, timeout=5) # TODO: remove this hardcode
res.raise_for_status()
page = res.read().decode('utf-8').strip()
assert page.startswith(data['callback'] + '({') and page.endswith('})')
page = page[len(data['callback']) + 1:-1]
Expand All @@ -100,17 +100,16 @@ def get(url, data, callback, dataType):
page = callback(page)
return page
elif dataType == 'raw':
data = copy.deepcopy(data)
data = parse.urlencode(data)
req = request.Request(url + '?' + data if data else url)
res = request.urlopen(req, timeout=5)
assert 200 == res.getcode()
res.raise_for_status()
page = res.read().decode('utf-8')
if callback:
page = callback(page)
return page
else:
raise NotImplementedError('get ~jsonp not implemented')
raise NotImplementedError
return None


Expand Down

0 comments on commit 67025e1

Please sign in to comment.