Repository: ytdl-org/youtube-dl

Issue:
[niconico] TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
### Make sure you are using the *latest* version: run `youtube-dl --version` and ensure your version is *2018.08.28*. If it's not, read [this FAQ entry](https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl) and update. Issues with outdated version will be rejected.
- [x] I've **verified** and **I assure** that I'm running youtube-dl **2018.08.28**

### Before submitting an *issue* make sure you have:
- [x] At least skimmed through the [README](https://github.com/rg3/youtube-dl/blob/master/README.md), **most notably** the [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones
- [x] Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser

### What is the purpose of your *issue*?
- [x] Bug report (encountered problems with youtube-dl)
- [ ] Site support request (request for adding support for a new site)
- [ ] Feature request (request for a new functionality)
- [ ] Question
- [ ] Other

---

### The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your *issue*

---

### If the purpose of this *issue* is a *bug report*, *site support request* or you are not completely sure provide the full verbose output as follows:

Add the `-v` flag to **your command line** you run youtube-dl with (`youtube-dl -v <your command line>`), copy the **whole** output and insert it here. It should look similar to one below (replace it with **your** log inserted between triple ```):

```
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['-v', 'http://www.nicovideo.jp/watch/sm33755147']
[debug] Encodings: locale cp932, fs mbcs, out cp932, pref cp932
[debug] youtube-dl version 2018.08.28
[debug] Python version 3.4.4 (CPython) - Windows-8.1-6.3.9600
[debug] exe versions: ffmpeg N-81256-gd3426fb, ffprobe N-81256-gd3426fb
[debug] Proxy map: {}
[niconico] sm33755147: Downloading webpage
[niconico] sm33755147: Downloading JSON metadata for h264_200kbps_360p-aac_64kbps
Traceback (most recent call last):
  File "__main__.py", line 19, in <module>
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\__init__.py", line 472, in main
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\__init__.py", line 462, in _real_main
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\YoutubeDL.py", line 2001, in download
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\YoutubeDL.py", line 792, in extract_info
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\extractor\common.py", line 502, in extract
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\extractor\niconico.py", line 343, in _real_extract
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\extractor\niconico.py", line 253, in _extract_format_for_quality
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\extractor\common.py", line 859, in _download_json
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\extractor\common.py", line 837, in _download_json_handle
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\extractor\common.py", line 627, in _download_webpage_handle
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\extractor\common.py", line 599, in _request_webpage
  File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc4srko6s\build\youtube_dl\YoutubeDL.py", line 2211, in urlopen
  File "C:\Python\Python34\lib\urllib\request.py", line 462, in open
  File "C:\Python\Python34\lib\urllib\request.py", line 1113, in do_request_
TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
```
---
### Description of your *issue*, suggested solution and other information

Error occurs for certain niconico URLs. I haven't tested extensively but it seems to occur exclusively on (some) recent videos (~July 2018).

e.g. http://www.nicovideo.jp/watch/sm33642362 -- works
     http://www.nicovideo.jp/watch/sm33755147 -- fails with above error





Discussion:
I'm seeing the same issue. Some videos work, some don't (though both of the examples given fail for me).

I also noticed that running youtube-dl with python2 instead of python3 works for every video I've tried.

Resolving patch:
diff --git a/youtube_dl/extractor/niconico.py b/youtube_dl/extractor/niconico.py
--- a/youtube_dl/extractor/niconico.py
+++ b/youtube_dl/extractor/niconico.py
@@ -252,7 +252,7 @@ def yesno(boolean):
                     },
                     'timing_constraint': 'unlimited'
                 }
-            }))
+            }).encode())
 
         resolution = video_quality.get('resolution', {})
 


Test patch: