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

AttributeError: 'LogOutputStream' object has no attribute 'buffer' #516

Closed
zhushenwudi opened this issue Jul 9, 2021 · 3 comments
Closed
Labels

Comments

@zhushenwudi
Copy link

zhushenwudi commented Jul 9, 2021

i use python3.8 and pip import you-get, program throw a exception like io error, i see you-get third-party that common.py line(23) is "sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')", I don’t know if this can be executed normally

Chaquopy version

9.1.0

Devices or emulators where the issue happens

real device and emulator

Relevant parts of your code

app gradle:

python {
    buildPython '/usr/local/bin/python3.8'
    pip {
        install "you-get"
    }
}

MainActivity.java:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val py = Python.getInstance()
        val str = py.getModule("test").callAttr("greet")
        Log.e("aaa",str.toString())
    }
}

test.py:

from you_get import common as you_get

def greet():
    url = "https://www.bilibili.com/video/BV1cV411s7c9"
    outputDir = r'/sdcard'
    you_get.any_download(url, info_only=False, output_dir=outputDir, merge=True)
    return "download finish"

Describe your issue

E: FATAL EXCEPTION: main
    Process: com.ilab.pythondemo, PID: 2203
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ilab.pythondemo/com.ilab.pythondemo.MainActivity}: com.chaquo.python.PyException: AttributeError: 'LogOutputStream' object has no attribute 'buffer'
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: com.chaquo.python.PyException: AttributeError: 'LogOutputStream' object has no attribute 'buffer'
        at <python>.you_get.common.<module>(common.py:23)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.test.<module>(test.py:1)
        at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
        at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:783)
        at <python>.java.android.importer.exec_module(importer.py:507)
        at <python>.java.android.importer.exec_module(importer.py:556)
        at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
        at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
        at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
        at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
        at <python>.importlib.import_module(__init__.py:127)
        at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModuleNative(chaquopy_java.pyx:155)
        at com.chaquo.python.Python.getModuleNative(Native Method)
        at com.chaquo.python.Python.getModule(Python.java:84)
        at com.ilab.pythondemo.MainActivity.onCreate(MainActivity.kt:13)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
@mhsmith mhsmith added the bug label Jul 9, 2021
@mhsmith
Copy link
Member

mhsmith commented Jul 9, 2021

This is caused by the same thing as #464, and we'll fix it in the next version of Chaquopy. Meanwhile, you can work around the problem like this:

import sys
so = sys.stdout
sys.stdout = sys.__stdout__
from you_get import common as you_get
sys.stdout = so

@zhushenwudi
Copy link
Author

nice,it works, 3Q!

@mhsmith
Copy link
Member

mhsmith commented Sep 22, 2021

This issue is fixed in Chaquopy 10.0.1. To upgrade, edit your app's top-level build.gradle file and change the version number of com.chaquo.python:gradle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants