mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
Merge pull request #269 from sonneveld/client-internal-call-refactor
Refactor client internal calls to allow keepalive
This commit is contained in:
commit
c2b6be6446
@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Allow session keepalive
|
||||||
|
|
||||||
## [2.6.1] - 2020-01-13
|
## [2.6.1] - 2020-01-13
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@ -113,44 +113,39 @@ class Spotify(object):
|
|||||||
|
|
||||||
if self.trace_out:
|
if self.trace_out:
|
||||||
print(url)
|
print(url)
|
||||||
r = self._session.request(
|
|
||||||
method,
|
with self._session.request(method, url, headers=headers,
|
||||||
url,
|
proxies=self.proxies, **args) as r:
|
||||||
headers=headers,
|
|
||||||
proxies=self.proxies,
|
|
||||||
**args)
|
|
||||||
|
|
||||||
if self.trace: # pragma: no cover
|
if self.trace: # pragma: no cover
|
||||||
print()
|
print()
|
||||||
print('headers', headers)
|
print('Request headers:', headers)
|
||||||
print('http status', r.status_code)
|
print('Response headers:', r.headers)
|
||||||
|
print('HTTP status', r.status_code)
|
||||||
print(method, r.url)
|
print(method, r.url)
|
||||||
if payload:
|
if payload:
|
||||||
print("DATA", json.dumps(payload))
|
print("Data", json.dumps(payload))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except BaseException:
|
except BaseException:
|
||||||
if r.text and len(r.text) > 0 and r.text != 'null':
|
try:
|
||||||
msg = '%s:\n %s' % (r.url, r.json()['error']['message'])
|
msg = r.json()['error']['message']
|
||||||
|
except BaseException:
|
||||||
|
msg = 'error'
|
||||||
raise SpotifyException(r.status_code,
|
raise SpotifyException(r.status_code,
|
||||||
-1, msg,
|
-1, '%s:\n %s' % (r.url, msg),
|
||||||
headers=r.headers)
|
headers=r.headers)
|
||||||
else:
|
|
||||||
raise SpotifyException(r.status_code,
|
try:
|
||||||
-1, '%s:\n %s' % (r.url, 'error'),
|
|
||||||
headers=r.headers)
|
|
||||||
finally:
|
|
||||||
if hasattr(r, "connection"):
|
|
||||||
r.connection.close()
|
|
||||||
if r.text and len(r.text) > 0 and r.text != 'null':
|
|
||||||
results = r.json()
|
results = r.json()
|
||||||
|
except BaseException:
|
||||||
|
results = None
|
||||||
|
|
||||||
if self.trace: # pragma: no cover
|
if self.trace: # pragma: no cover
|
||||||
print('RESP', results)
|
print('Response:', results)
|
||||||
print()
|
print()
|
||||||
return results
|
return results
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _get(self, url, args=None, payload=None, **kwargs):
|
def _get(self, url, args=None, payload=None, **kwargs):
|
||||||
if args:
|
if args:
|
||||||
|
|||||||
@ -203,6 +203,7 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
with_custom_session.user(
|
with_custom_session.user(
|
||||||
user="akx")["uri"] == "spotify:user:akx")
|
user="akx")["uri"] == "spotify:user:akx")
|
||||||
|
sess.close()
|
||||||
|
|
||||||
def test_force_no_requests_session(self):
|
def test_force_no_requests_session(self):
|
||||||
with_no_session = Spotify(auth=self.token, requests_session=False)
|
with_no_session = Spotify(auth=self.token, requests_session=False)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user