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: 'str' object has no attribute 'write' en android #22109

Open
python-ab opened this issue Aug 15, 2019 · 2 comments
Open

AttributeError: 'str' object has no attribute 'write' en android #22109

python-ab opened this issue Aug 15, 2019 · 2 comments

Comments

@python-ab
Copy link

@python-ab python-ab commented Aug 15, 2019

I am trying to download audio and videos using kivy. the code works fine in windows and ubuntu but generates an error in android.

This is the code:

importar youtube_dl

import kivy
kivy.require ('1.11.0')

from kivy.app import App
de kivy.uix.boxlayout import BoxLayout

desde kivy.config import Config
Config.set ('gráficos', 'ancho', 400)
Config.set ('gráficos', 'alto', 200)

clase Contenedor_01 (BoxLayout):

def descargarA(self):
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=2j3x0VYnehg'])
clase MainApp (aplicación):
def build (self):
return Contenedor_01 ()

if name == ' main ':
MainApp (). run ()

I get this error:

I / python (20086): Android kivy bootstrap hecho. el nombre es I / python principal
(20086): AND: Ran string
I / python (20086): Ejecute el programa de usuario, cambie el directorio y ejecute el punto de entrada
I / python (20086): [ADVERTENCIA] [Config] Versión de configuración anterior detectada (0 en su lugar de 21)
I / python (20086): [ADVERTENCIA] [Config] Actualización de la configuración en progreso.
I / python (20086): [INFO] [Logger] Registro de registro en /data/user/0/org.test.downloadmeapp/files/app/.kivy/logs/kivy_19-08-15_0.txt
I / python (20086 ): [INFO] [Kivy] v1.11.0
I / python (20086): [INFO] [Kivy] instalado en "/data/user/0/org.test.downloadmeapp/files/app/_python_bundle/site-packages/ kivy /init .pyc "
I / python (20086): [INFO] [Python] v3.7.1 (predeterminado, 15 de agosto de 2019, 15:27:31)
I / python (20086): [Clang 6.0.2 (https: // android.googlesource.com/toolchain/clang 183abd29fc496f55
I / python (20086): [INFO] [Python] Intérprete en "android_python"
I / python (20086): [INFO] [Factory] 184 símbolos cargados
I / python (20086) : [INFO] [Imagen] Proveedores: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignorado)
I / python (20086): [INFO] [Window] Proveedor: sdl2
I / python (20086): [INFO] [GL ] Utilizando el sistema gráfico "OpenGL ES 2"
I / python (20086): [INFO] [GL] Backend utilizado
I / python (20086): [INFO] [GL] OpenGL versión <b'OpenGL ES 3.1 V@140.0 (GIT @ Iec24cdb30f) '>
I / python (20086): [INFO] [GL] Proveedor de OpenGL <b'Qualcomm '>
I / python (20086): [INFO] [GL] Procesador de OpenGL <b'Adreno (TM) 405'>
I / python (20086): [INFO] [GL] Versión analizada de OpenGL: 3, 1
I / python (20086): [INFO] [GL] Tamaño máximo de textura <16384>
I / python (20086): [INFO] [GL] Unidades máximas de textura <16>
I / python (20086): [INFO] [Ventana] auto agregar proveedor de entrada sdl2
I / python (20086): [INFO] [Ventana] teclado virtual no permitido, modo único, no acoplado
I / python (20086): [INFO] [Texto] Proveedor: sdl2
I / python (20086): [ADVERTENCIA] [Base] Proveedor desconocido
I / python (20086): [INFO] [Base] Iniciar el bucle principal de la aplicación
I / python (20086): [INFO] [GL] El soporte de textura NPOT está disponible
I / python (20086): [INFO] [Base] Dejando la aplicación en progreso ...
I / python (20086): Traceback (última llamada):
I / python (20086): Archivo "/ home / abrahan / Escritorio /prueba/.buildozer/android/app/main.py ", línea 38, en
I / python (20086): Archivo" /home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python- instala / DownLoadMeApp / kivy / app.py ", línea 855, en ejecución
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/base.py", línea 504, en runTouchApp
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/core/window/window_sdl2.py", línea 746, en mainloop
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/core/window/window_sdl2.py", línea 478, en _mainloop
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/base.py", línea 342, en inactivo
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/base.py", línea 327, en dispatch_input
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/base.py", línea 233, en post_dispatch_input
I / python (20086) : Archivo "kivy / _event.pyx", línea 707, en kivy._event.EventDispatcher.dispatch
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/ python-installs / DownLoadMeApp / kivy / core / window / init .py ", línea 1378, en on_motion
I / python (20086): Archivo" kivy / _event.pyx ", línea 707, en kivy._event.EventDispatcher.dispatch
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/core/window/ init .py", línea 1394, en on_touch_down
I / python (20086): Archivo "kivy / _event.pyx", línea 707, en kivy._event.EventDispatcher.dispatch
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android /platform/build/build/python-installs/DownLoadMeApp/kivy/uix/widget.py ", línea 549, en on_touch_down
I / python (20086): Archivo" kivy / _event.pyx ", línea 707, en kivy._event .EventDispatcher.dispatch
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/kivy/uix/behaviors/button.py", línea 151,en on_touch_down
I / python (20086): archivo "kivy / _event.pyx", línea 703, en kivy._event.EventDispatcher.dispatch
I / python (20086): archivo "kivy / _event.pyx", línea 1214, en kivy._event .EventObservers.dispatch
I / python (20086): Archivo "kivy / _event.pyx", línea 1098, en kivy._event.EventObservers._dispatch
I / python (20086): Archivo "/ home / abrahan / Escritorio / prueba /. buildozer / android / platform / build / build / python-installs / DownLoadMeApp / kivy / lang / builder.py ", línea 64, en custom_callback
I / python (20086): Archivo" /data/data/org.test.downloadmeapp/ files / app / main.kv ", línea 4, en
I / python (20086): on_press: root.descargarA ()
I / python (20086): File" /home/abrahan/Escritorio/prueba/.buildozer/android/ app / main.py ", línea 29,en descargarA
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/YoutubeDL.py", línea 2010, en descarga
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/YoutubeDL.py", línea 796, en extract_info
I / python (20086) : Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/common.py", línea 530, en extracto
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/youtube.py", línea 1668, en _real_extract
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/common.py", línea 794, en _download_webpage
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/youtube.py", línea 274, en _download_webpage_handle
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/common.py", línea 660, en _download_webpage_handle
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/common.py", línea 602,en _request_webpage
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/common.py", línea 922, en report_download_webpage
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/extractor/common.py", línea 914, en to_screen
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/YoutubeDL.py", línea 502, en la pantalla
I / python (20086 ): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/YoutubeDL.py", línea 516, en to_stdout
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/YoutubeDL.py", línea 505, en _write_string
I / python (20086): Archivo "/home/abrahan/Escritorio/prueba/.buildozer/android/platform/build/build/python-installs/DownLoadMeApp/youtube_dl/utils.py", línea 3084, en write_string
I / python (20086) : AttributeError: el objeto 'str' no tiene atributo 'write'
I / python (20086): Python para Android finalizó.

I can't solve this problem

@robertjankowski
Copy link

@robertjankowski robertjankowski commented Sep 8, 2019

I have a very similar issue. When I use youtube-dl without Kivy everything works fine. However, when I try to combine youtube-dl in my Kivy app I receive the following error:

Traceback (most recent call last):
File ".../yt-music-converter/scripts/ui/example.py", line 21, in
ydl.download(['https://www.youtube.com/watch?v=xKJkzro8ArA'])
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 2010, in download
url, force_generic_extractor=self.params.get('force_generic_extractor', False))
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 807, in extract_info
return self.process_ie_result(ie_result, download, extra_info)
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 861, in process_ie_result
return self.process_video_result(ie_result, download=download)
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 1642, in process_video_result
self.process_info(new_info)
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 1894, in process_info
'Requested formats are incompatible for merge and will be merged into mkv.')
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 612, in report_warning
self.to_stderr(warning_message)
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 526, in to_stderr
self._write_string(output, self._err_file)
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 505, in _write_string
write_string(s, out=out, encoding=self.params.get('encoding'))
File "...\yt-music-converter\venv\lib\site-packages\youtube_dl\utils.py", line 3084, in write_string
out.buffer.write(byt)
AttributeError: 'str' object has no attribute 'write'


Here is a reproducible example

This fails:

import youtube_dl
from kivy.app import App
from kivy.uix.button import Button


class MusicApp(App):
    def build(self):
        return Button(text='Example')


ydl_opts = {
    'outtmpl': '%(title)s.%(ext)s',
    'audio-format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=xKJkzro8ArA'])

When I remove Kivy dependencies it works:

import youtube_dl

ydl_opts = {
    'outtmpl': '%(title)s.%(ext)s',
    'audio-format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=xKJkzro8ArA'])
@adarsh1783
Copy link

@adarsh1783 adarsh1783 commented Jun 22, 2020

I am getting the same error. Have anyone of you solved this issue ??

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.