arxanchain / py-common

python common packages
Apache License 2.0
1 stars 5 forks source link

"404 page not found" caused ValueError #8

Closed ivy-dong closed 6 years ago

ivy-dong commented 6 years ago

when I got "404 page not found" from server. then py-common shows me error: ValueError: Extra data: line 1 column 5 - line 1 column 19 (char 4 - 18)

(ex: query qoe with wallet-sdk-py, the url may v1/poe/:, I will get "404 page not found" from server. )

see rest/api/api.py

    ## Decrypt and verify
    plain_body = decrypt_and_verify(resp.text, apikey, cert_path)  #plain_body="404 page not found"
    return json.loads(plain_body) #error

Traceback (most recent call last):

  File "integrate_test_wallet.py", line 157, in <module>
    q_poe_name,q_poe_guardian = query_poe(poeclient, c_poe_id)
  File "integrate_test_wallet.py", line 109, in query_poe
    _, resp = q_poe.do_request(poeclient)
  File "/Users/yan/work/gospace/src/github.com/plumber/ci/integration/baas/v1.3/040_wallet-ng/py/structs.py", line 173, in do_request
    return poeclient.query({}, self.id_)
  File "/usr/local/lib/python2.7/site-packages/wallet_sdk_py-1.5.0-py2.7.egg/api/poe.py", line 108, in query
    method,
  File "/usr/local/lib/python2.7/site-packages/py_common-1.5.0-py2.7.egg/rest/api/api.py", line 127, in do_request
    apikey, cert_path)
  File "/usr/local/lib/python2.7/site-packages/py_common-1.5.0-py2.7.egg/rest/api/api.py", line 104, in require_ok
    return json.loads(plain_body)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 367, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 5 - line 1 column 19 (char 4 - 18)
Honghaohan2013 commented 6 years ago

We added "ClientErrMsg" field into dictionary that function rest.api.api.require_ok returned, you can use it to find if response body is cipher or not, when resp body is not cipher or decrypt_and_verify function raises Exception, the content will be the response body; when body is empty, the content will be a self-defined error message. If response body is successfully decrypted, the content will be "".