Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url with gbk encode report UnicodeDecodeError #578

Closed
rogerdehe opened this issue Apr 27, 2017 · 2 comments
Closed

url with gbk encode report UnicodeDecodeError #578

rogerdehe opened this issue Apr 27, 2017 · 2 comments

Comments

@rogerdehe
Copy link

I have an API which use gbk encode, I have to call like this:

echo http://10.202.15.197:20176?user_id=1&query_type=GEOSPLIT&address=广东省深圳市宝安&ret_splitinfo=1 | iconv -f utf-8 -t gbk | xargs curl | iconv -f gbk -t utf-8

but if I change cURL to httpie it will report :

Traceback (most recent call last):
  File "/usr/bin/http", line 11, in <module>
    load_entry_point('httpie==0.9.8', 'console_scripts', 'http')()
  File "/usr/lib/python2.7/dist-packages/httpie/__main__.py", line 11, in main
    sys.exit(main())
  File "/usr/lib/python2.7/dist-packages/httpie/core.py", line 182, in main
    args = decode_args(args, env.stdin_encoding)
  File "/usr/lib/python2.7/dist-packages/httpie/core.py", line 71, in decode_args
    for arg in args
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb9 in position 65: invalid start byte
@GotoCode
Copy link
Contributor

Is it possible that the arguments to iconv have been supplied in reverse?

From what I understand, since the URL uses the GBK encoding, I believe this part of your code:

... | iconv -f utf-8 -t gbk | xargs http | iconv -f gbk -t utf-8

...should actually be written as:

... | iconv -f gbk -t utf-8 | xargs http | iconv -f utf-8 -t gbk

@BoboTiG
Copy link
Contributor

BoboTiG commented Sep 22, 2021

I think @GotoCode has found the issue and fix 🥧

Please feel free to reopen this if you still have the issue/questions.

@BoboTiG BoboTiG closed this as completed Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants