question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: must be str, not bytes

See original GitHub issue

Versions

  • Python: 3.5.3 (running in virtualenv and in root) (seems to be running Python 3.7.1 on Android based on the logs)
  • OS: Ubuntu 17:04
  • Kivy: 1.9.1
  • Cython: 0.28.6
  • Andoid 7.0 (on Samsung Galaxy S6)

Description

I have compiled a very basic helloWorld app as below. The app works fine on Ubuntu and also compiles fine into apk using buildozer.

__version__ = '1.0'
from kivy.app import App
from kivy.uix.button import Button
 
class Hello(App):
    def build(self):
        btn = Button(text='Hello World')
        return  btn
 
Hello().run()

When I run on Android the app immediately closes before displaying the hello world screen. After working through logs produced with adb logcat I see the following…

06-25 19:48:52.272  2100  2118 I python  :  Traceback (most recent call last):
06-25 19:48:52.272  2100  2118 I python  :    File "/home/lee/KivyProjects/helloWorld/.buildozer/android/app/main.py", line 3, in <module>
06-25 19:48:52.273  2100  2118 I python  :    File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/kivy/app.py", line 319, in <module>
06-25 19:48:52.273  2100  2118 I python  :    File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/kivy/base.py", line 26, in <module>
06-25 19:48:52.274  2100  2118 I python  :    File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/kivy/clock.py", line 410, in <module>
06-25 19:48:52.274  2100  2118 I python  :    File "<frozen importlib._bootstrap>", line 983, in _find_and_load
06-25 19:48:52.274  2100  2118 I python  :    File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
06-25 19:48:52.275  2100  2118 I python  :    File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
06-25 19:48:52.275  2100  2118 I python  :    File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
06-25 19:48:52.276  2100  2118 I python  :    File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/util.py", line 73, in <module>
06-25 19:48:52.276  2100  2118 I python  :    File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/android/__init__.py", line 8, in <module>
06-25 19:48:52.277  2100  2118 I python  :    File "android/_android.pyx", line 162, in init android._android
06-25 19:48:52.277  2100  2118 I python  :  TypeError: must be str, not bytes
06-25 19:48:52.277  2100  2118 I python  : Python for android ended.

This appears to be the same issue raised as 1691 under the title “unicode error during startup (python3, numpy, opencv) - patch included #1691”. If I am reading this patch correctly the current file _android.pyx should have the following changes

removed this line python_act = autoclass(JAVA_NAMESPACE + u’.PythonActivity’)

added these lines java_namespace = JAVA_NAMESPACE.decode() if isinstance(JAVA_NAMESPACE, bytes) else JAVA_NAMESPACE python_act = autoclass(java_namespace + u’.PythonActivity’)

Yet when I look at the current code on Github for _android.pyx I do not see these changes applied. Has this fix somehow been removed from the current version? How can i apply this fix to my system?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:31 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ghostcommented, Jun 29, 2019

I just looked at the code in pythonforandroid/build.py and it seems to me this is a bug, it uses “Cython” as a binary rather than using sys.executable/python2/python3 -m cython which should probably fix this. I’ll see if I can change that, it seems fixable to me

1reaction
ghostcommented, Jun 28, 2019

@synccodes did you try sudo pip uninstall cython, pip uninstall cython (to make sure it’s gone from all places) and then sudo pip3 install cython? If it’s really cython being installed via python 2 that should possibly fix it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 3 TypeError: must be str, not bytes with sys.stdout.write()
In your specific piece of code, nextline is of type bytes , not str , reading stdout and stdin from subprocess changed in...
Read more >
Why is 'TypeError: must be str, not bytes' error? - Quora
Basically, this error tells you that the element you were trying to select was not found (hence, it cannot find the “style” property...
Read more >
TypeError: write() argument must be str, not bytes (Python)
The Python "TypeError: write() argument must be str, not bytes" occurs when we try to write bytes to a file without opening the...
Read more >
Solved - TypeError: write() argument must be str, not bytes in ...
The error "TypeError: write() argument must be str, not bytes" occurs when we try to write bytes to a file which is not...
Read more >
TypeError: must be str, not bytes - Python Forum
TypeError : must be str, not bytes ; replace bytes with other byte or bytes · builtins.TypeError: a bytes-like object is required, not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found