Fixed "Connetion reset by peer" issue
This commit is contained in:
parent
a837389e8b
commit
d8fe37f1ee
|
@ -6,6 +6,8 @@ from Crypto.Cipher import Blowfish
|
||||||
import pyaes
|
import pyaes
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
|
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +31,7 @@ class Deezer:
|
||||||
return token_data["results"]["checkForm"]
|
return token_data["results"]["checkForm"]
|
||||||
|
|
||||||
def get_track_md5(self, sng_id):
|
def get_track_md5(self, sng_id):
|
||||||
|
try:
|
||||||
site = self.session.post(
|
site = self.session.post(
|
||||||
"https://api.deezer.com/1.0/gateway.php",
|
"https://api.deezer.com/1.0/gateway.php",
|
||||||
params={
|
params={
|
||||||
|
@ -38,13 +41,18 @@ class Deezer:
|
||||||
'output': '3',
|
'output': '3',
|
||||||
'method': 'song_getData'
|
'method': 'song_getData'
|
||||||
},
|
},
|
||||||
|
timeout=30,
|
||||||
json={'sng_id': sng_id},
|
json={'sng_id': sng_id},
|
||||||
headers=self.http_headers
|
headers=self.http_headers
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
time.wait(2)
|
||||||
|
return self.get_track_md5(sng_id)
|
||||||
response = site.json()
|
response = site.json()
|
||||||
return response['results']['PUID']
|
return response['results']['PUID']
|
||||||
|
|
||||||
def gw_api_call(self, method, args={}):
|
def gw_api_call(self, method, args={}):
|
||||||
|
try:
|
||||||
result = self.session.post(
|
result = self.session.post(
|
||||||
self.api_url,
|
self.api_url,
|
||||||
params={
|
params={
|
||||||
|
@ -53,18 +61,27 @@ class Deezer:
|
||||||
'input': '3',
|
'input': '3',
|
||||||
'method': method
|
'method': method
|
||||||
},
|
},
|
||||||
|
timeout=30,
|
||||||
json=args,
|
json=args,
|
||||||
headers=self.http_headers
|
headers=self.http_headers
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
time.wait(2)
|
||||||
|
return self.gw_api_call(method, args)
|
||||||
return result.json()
|
return result.json()
|
||||||
|
|
||||||
def api_call(self, method, args={}):
|
def api_call(self, method, args={}):
|
||||||
|
try:
|
||||||
result = self.session.get(
|
result = self.session.get(
|
||||||
self.legacy_api_url + method,
|
self.legacy_api_url + method,
|
||||||
params=args,
|
params=args,
|
||||||
headers=self.http_headers
|
headers=self.http_headers,
|
||||||
|
timeout=30
|
||||||
)
|
)
|
||||||
result_json = result.json()
|
result_json = result.json()
|
||||||
|
except:
|
||||||
|
time.wait(2)
|
||||||
|
return self.api_call(method, args)
|
||||||
if 'error' in result_json.keys():
|
if 'error' in result_json.keys():
|
||||||
raise APIError()
|
raise APIError()
|
||||||
return result_json
|
return result_json
|
||||||
|
|
Loading…
Reference in New Issue