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

'gbk' codec can't decode byte #399

Closed
Vopaaz opened this issue Oct 14, 2019 · 7 comments
Closed

'gbk' codec can't decode byte #399

Vopaaz opened this issue Oct 14, 2019 · 7 comments
Assignees
Labels
type:bug Something isn't working

Comments

@Vopaaz
Copy link

Vopaaz commented Oct 14, 2019

Summary

Issue #281 not solved after upgrading.

Getting a similar Script execution error:

'gbk' codec can't decode byte 0x94 in position 987: illegal multibyte sequence

after upgrading to streamlit-0.48.1

Steps to reproduce

Run streamlit hello.

Expected behavior:

Streamlit hello examples

Actual behavior:

Explain the buggy behavior you experience when you go through the steps above.
If applicable, add screenshots to help explain your problem.

Is this a regression?

No

Debug info

  • Streamlit version: Streamlit, version 0.48.1
  • Python version: Python 3.7.2
  • OS version: Windows 10
  • Browser version: Google Chrome 77.0.3865.90
@Vopaaz Vopaaz added the type:bug Something isn't working label Oct 14, 2019
@jh-lau
Copy link

jh-lau commented Oct 14, 2019

same as before with streamlit hello get 'gbk' codec can't decode issue
but Chinese character would not produce this error now in my own script, although it didn't decode in right way

Debug info

  • streamlit version: 0.48.1
  • python version: 3.6.2
  • OS: windows10
  • Browser: Chromium 74.0.3729.169

@Vopaaz
Copy link
Author

Vopaaz commented Oct 14, 2019

Could it possibly be fixed by adding encoding="utf-8" (or other encoding your hello example is using) to the following with open statement?

with open(self._report.script_path) as f:

On your contributing wiki page, there are no instructions on developing on Windows machine (and I have tried it but failed), so I am not able to test it.

@tvst
Copy link
Contributor

tvst commented Oct 17, 2019

Hi all

I can reproduce this issue on my Windows VM, but I'm having a hard time finding a solution. Just setting the encoding as proposed by @Vopaaz doesn't seem to work.

Even worse, even this simple test fails for me:

  1. Write a file called "chinese_characters.txt" and enter a chinese character there, like
  2. On a terminal, navigate to the folder where the file above lives
  3. Type python -m http.server
  4. Go to localhost:8000/chinese_characters.txt on your browser

Expected: you should see in the browser
Actual: you see 例 in the browser

This test doesn't even use Streamlit. Just pure Python. So I'm at a loss regarding how to solve it...

We'll keep testing over here but if anyone has any other ideas, please let us know!

@tvst
Copy link
Contributor

tvst commented Oct 17, 2019

Actually, I just realized I didn't test @Vopaaz's solution correctly.

Trying it out again, it actually works!

So I'll send out a pull request right now.

Thanks @Vopaaz !

@Vopaaz
Copy link
Author

Vopaaz commented Oct 17, 2019

@tvst You are welcome!

I have already submitted a PR right before you made these comments. Please take a look at the Python 2 issue I mentioned here #440 (comment). Please feel free to make any modifications as I am not familiar with Python 2!

@mengyou658
Copy link

when use st.echo(): include Chinese chars flow this error:

UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 40: illegal multibyte sequence
File "d:\anaconda3\envs\demo-machine\lib\site-packages\streamlit\ScriptRunner.py", line 312, in _run_script exec(code, module.__dict__)
File "E:\pass\demo\demo-machine-learn\pytorchdemo\demo-3-6-softmax-1.py", line 54, in <module> b.requires_grad_(requires_grad=True)
File "d:\anaconda3\envs\demo-machine\lib\contextlib.py", line 88, in __exit__ next(self.gen)
File "d:\anaconda3\envs\demo-machine\lib\site-packages\streamlit\__init__.py", line 542, in echo source_lines = source_file.readlines()

flow is the demo.py content

# encoding: utf-8
# -*- coding: utf8 -*-
'''
中文
'''
import streamlit as st
with st.echo():
  num_inputs = 784

Debug info

  • Streamlit version: Streamlit, version 0.48.1
  • Python version: Python 3.6.9 :: Anaconda, Inc.
  • Using Conda
  • OS version: Windows 10 (GBK)
  • Browser version: google chrome 77.0.3865.120

@tvst
Copy link
Contributor

tvst commented Oct 17, 2019

Thanks for the bug report @mengyou658 , I've added that fix to my PR here

@tvst tvst self-assigned this Oct 17, 2019
@tvst tvst closed this as completed in 1c47ec7 Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants