mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
fix
Update requests.py Update requests.py
This commit is contained in:
parent
8e46c79957
commit
0e950a63cb
@ -122,7 +122,7 @@ def updatemethod(_version, progresscallback):
|
|||||||
file_size += thislen
|
file_size += thislen
|
||||||
|
|
||||||
progresscallback(
|
progresscallback(
|
||||||
"总大小{} MB 进度 {}% ".format(
|
"总大小{} MB 进度 {:0.2f}% ".format(
|
||||||
int(1000 * (int(size / 1024) / 1024)) / 1000,
|
int(1000 * (int(size / 1024) / 1024)) / 1000,
|
||||||
int(10000 * (file_size / size)) / 100,
|
int(10000 * (file_size / size)) / 100,
|
||||||
),
|
),
|
||||||
|
@ -131,6 +131,7 @@ class Session(Sessionbase):
|
|||||||
cookies.update(self.cookies)
|
cookies.update(self.cookies)
|
||||||
else:
|
else:
|
||||||
cookies = self.cookies
|
cookies = self.cookies
|
||||||
|
curl_easy_reset(curl)
|
||||||
if cookies:
|
if cookies:
|
||||||
cookie = self._parsecookie(cookies)
|
cookie = self._parsecookie(cookies)
|
||||||
curl_easy_setopt(curl, CURLoption.CURLOPT_COOKIE, cookie.encode("utf8"))
|
curl_easy_setopt(curl, CURLoption.CURLOPT_COOKIE, cookie.encode("utf8"))
|
||||||
@ -201,31 +202,43 @@ class Session(Sessionbase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def ___perform():
|
def ___perform():
|
||||||
|
error = False
|
||||||
try:
|
try:
|
||||||
self._perform(curl)
|
self._perform(curl)
|
||||||
except:
|
except:
|
||||||
print_exc()
|
print_exc()
|
||||||
self.raise_for_status()
|
|
||||||
headerqueue.put(None)
|
headerqueue.put(None)
|
||||||
curl_easy_reset(curl)
|
error = True
|
||||||
resp.queue.put(None)
|
resp.queue.put(None)
|
||||||
|
if error:
|
||||||
|
print(url)
|
||||||
|
self.raise_for_status()
|
||||||
|
|
||||||
threading.Thread(target=___perform, daemon=True).start()
|
threading.Thread(target=___perform, daemon=True).start()
|
||||||
|
|
||||||
headerb = b""
|
headerb = ""
|
||||||
|
cnt = 1
|
||||||
while True:
|
while True:
|
||||||
_headerb = headerqueue.get()
|
_headerb = headerqueue.get()
|
||||||
if _headerb is None:
|
if _headerb is None:
|
||||||
self.raise_for_status()
|
self.raise_for_status()
|
||||||
headerb += _headerb
|
_headerb = _headerb.decode("utf8")
|
||||||
if _headerb == b"\r\n":
|
|
||||||
|
if _headerb.endswith(
|
||||||
|
"200 Connection established\r\n"
|
||||||
|
): # HTTP/1.1 200 Connection established\r\n
|
||||||
|
cnt += 1
|
||||||
|
elif _headerb == "\r\n":
|
||||||
|
cnt -= 1
|
||||||
|
if cnt == 0:
|
||||||
break
|
break
|
||||||
resp.headers = self._update_header_cookie(headerb.decode("utf8"))
|
else:
|
||||||
|
headerb += _headerb
|
||||||
|
|
||||||
|
resp.headers = self._update_header_cookie(headerb)
|
||||||
|
|
||||||
if proxy:
|
if proxy:
|
||||||
resp.status_code = int(
|
resp.status_code = int(headerb[:-2].split(" ")[1])
|
||||||
headerb.decode("utf8").split("\r\n")[0].split(" ")[1]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
resp.status_code = self._getStatusCode(curl)
|
resp.status_code = self._getStatusCode(curl)
|
||||||
else:
|
else:
|
||||||
@ -259,7 +272,7 @@ class Session(Sessionbase):
|
|||||||
resp.content = b"".join(_content)
|
resp.content = b"".join(_content)
|
||||||
resp.headers = self._update_header_cookie(b"".join(_headers).decode("utf8"))
|
resp.headers = self._update_header_cookie(b"".join(_headers).decode("utf8"))
|
||||||
resp.status_code = self._getStatusCode(curl)
|
resp.status_code = self._getStatusCode(curl)
|
||||||
curl_easy_reset(curl)
|
|
||||||
resp.last_error = self.last_error
|
resp.last_error = self.last_error
|
||||||
resp.cookies = self.cookies
|
resp.cookies = self.cookies
|
||||||
return resp
|
return resp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user