title: AttributeError: 'str' object has no attribute 'write', youtube-dl kivy
body: <p>I am currently working on a small project which requies youtube-dl to work kivy environment. I have python 3.8.3, Kivy 1.11.1, youtube-dl 2020.5.8. Other than this issue kivy is working fine with python3.8.</p>
  <p>I get this error <code>AttributeError: 'str' object has no attribute 'write'</code> while try to fetch information about a youtube video using youtube-dl</p>
  <p>It does works with a few link and does not work with many others.</p>
  <p>This error has already is already present on youtube-dl's github page [[here]][1], but I could not find any solution.</p>
  <p>These are the two following cases with a reproducible example.</p>
  <p><strong>Case 1</strong></p>
  <pre><code>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=BaW_jenozKc'])
  </code></pre>
  <p><em><strong>Output</strong></em></p>
  <pre><code>[INFO   ] [Logger      ] Record log in /home/adarsh/.kivy/logs/kivy_20-06-23_1.txt
  [INFO   ] [Kivy        ] v1.11.1
  [INFO   ] [Kivy        ] Installed at &quot;/usr/local/lib/python3.8/dist-packages/kivy/__init__.py&quot;
  [INFO   ] [Python      ] v3.8.2 (default, Apr 27 2020, 15:53:34) 
  [GCC 9.3.0]
  [INFO   ] [Python      ] Interpreter at &quot;/usr/bin/python3&quot;
  [INFO   ] [Factory     ] 184 symbols loaded
  [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
  [INFO   ] [Text        ] Provider: sdl2(['text_pango'] ignored)
  [youtube] BaW_jenozKc: Downloading webpage
  [download] Resuming download at byte 215799
  [download] Destination: youtube-dl test video ''_ä↭.f137.mp4
  [download] 100% of 2.11MiB in 00:07.90KiB/s ETA 00:00
  [download] Destination: youtube-dl test video ''_ä↭.f140.m4a
  [download] 100% of 154.06KiB in 00:00.07KiB/s ETA 00:00
  [ffmpeg] Merging formats into &quot;youtube-dl test video ''_ä↭.mp4&quot;
  Deleting original file youtube-dl test video ''_ä↭.f137.mp4 (pass -k to keep)
  Deleting original file youtube-dl test video ''_ä↭.f140.m4a (pass -k to keep)
  [ffmpeg] Destination: youtube-dl test video ''_ä↭.mp3
  Deleting original file youtube-dl test video ''_ä↭.mp4 (pass -k to keep)
  </code></pre>
  <p><strong>Case 2</strong></p>
  <pre><code>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=nTj4wVJAbNg'])
  </code></pre>
  <p><em><strong>Output</strong></em></p>
  <pre><code>[INFO   ] [Logger      ] Record log in /home/adarsh/.kivy/logs/kivy_20-06-23_2.txt
  [INFO   ] [Kivy        ] v1.11.1
  [INFO   ] [Kivy        ] Installed at &quot;/usr/local/lib/python3.8/dist-packages/kivy/__init__.py&quot;
  [INFO   ] [Python      ] v3.8.2 (default, Apr 27 2020, 15:53:34) 
  [GCC 9.3.0]
  [INFO   ] [Python      ] Interpreter at &quot;/usr/bin/python3&quot;
  [INFO   ] [Factory     ] 184 symbols loaded
  [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
  [INFO   ] [Text        ] Provider: sdl2(['text_pango'] ignored)
  [youtube] nTj4wVJAbNg: Downloading webpage
   Traceback (most recent call last):
     File &quot;temp/tmp.py&quot;, line 21, in &lt;module&gt;
       ydl.download(['https://www.youtube.com/watch?v=nTj4wVJAbNg'])
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 2018, in download
       res = self.extract_info(
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 808, in extract_info
       return self.process_ie_result(ie_result, download, extra_info)
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 863, in process_ie_result
       return self.process_video_result(ie_result, download=download)
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 1644, in process_video_result
       self.process_info(new_info)
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 1902, in process_info
       self.report_warning(
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 613, in report_warning
       self.to_stderr(warning_message)
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 527, in to_stderr
       self._write_string(output, self._err_file)
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py&quot;, line 506, in _write_string
       write_string(s, out=out, encoding=self.params.get('encoding'))
     File &quot;/home/adarsh/.local/lib/python3.8/site-packages/youtube_dl/utils.py&quot;, line 3174, in write_string
       out.buffer.write(byt)
   AttributeError: 'str' object has no attribute 'write'
  </code></pre>
  <p>Please suggest even if there are some workarounds.</p>
  <p><strong>EDIT</strong> :
  I passed a logger to youtube-dl taken from their github page</p>
  <pre><code>class MyLogger(object):
      def debug(self, msg):
          print(&quot;DEBUG &quot; + msg)
          pass
  
      def warning(self, msg):
          print(&quot;WARNING &quot; + msg)
          pass
  
      def error(self, msg):
          print(&quot;ERROR &quot; + msg)
  </code></pre>
  <p>I needed to write my own logger at later point to get the progress of download. So I am going with this solution.
  [1]: <a href="https://github.com/ytdl-org/youtube-dl/issues/22109" rel="nofollow noreferrer">https://github.com/ytdl-org/youtube-dl/issues/22109</a></p>