weixin_39575648
weixin_39575648
2020-12-26 20:43

Unable to use braintree_python on Google App Engine

AI responses are gzip-encoded, but the python library (probably the requests library) treats them as ASCII.


File "xtras/braintree/customer.py", line 126, in find
    return Configuration.gateway().customer.find(customer_id)
  File "xtras/braintree/customer_gateway.py", line 36, in find
    response = self.config.http().get("/customers/" + customer_id)
  File "xtras/braintree/util/http.py", line 57, in get
    return self.__http_do("GET", path)
  File "xtras/braintree/util/http.py", line 82, in __http_do
    return XmlUtil.dict_from_xml(response_body)
  File "xtras/braintree/util/xml_util.py", line 11, in dict_from_xml
    return Parser(xml).parse()
  File "xtras/braintree/util/parser.py", line 15, in __init__
    self.doc = minidom.parseString(">\s+

Modifying http_do() in util/http.py to unzip the content, makes the library work again, but this is probably a fragile way to fix this. (unzip() is just a wrapper to unzip raw data, nothing special.)


   def http_do(self, http_verb, path, headers, request_body):
        response = self.__request_function(http_verb)(
            self.environment.base_url + path,
            headers=headers,
            data=request_body,
            verify=self.environment.ssl_certificate,
            timeout=self.config.timeout
        )
        if response.headers['content-encoding']=='gzip':
            return [response.status_code, unzip(response.content)]
        else:
            return [response.status_code, response.text]

该提问来源于开源项目:braintree/braintree_python

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

6条回答