fix garbled-code bug of python http-api, uniform encoding to utf8 (#93)

This commit is contained in:
AOZMH 2020-09-26 11:35:16 +08:00 committed by GitHub
parent 7636056cb6
commit 62940eea10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -50,14 +50,17 @@ class GstoreConnector:
def Get(self, strUrl):
r = requests.get(self.Url + self.UrlEncode(strUrl))
r.encoding = "utf-8"
return r.text
def Post(self, strUrl, strPost):
r = requests.post(self.Url + self.UrlEncode(strUrl), strPost)
r.encoding = "utf-8"
return r.text
def fGet(self, strUrl, filename):
r = requests.get(self.Url + self.UrlEncode(strUrl), stream=True)
r.encoding = "utf-8"
with open(filename, 'wb') as fd:
for chunk in r.iter_content(4096):
fd.write(chunk)
@ -66,6 +69,7 @@ class GstoreConnector:
def fPost(self, strUrl, strPost, filename):
r = requests.post(self.Url + self.UrlEncode(strUrl),
strPost, stream=True)
r.encoding = "utf-8"
with open(filename, 'wb') as fd:
for chunk in r.iter_content(4096):
fd.write(chunk)