# urllib.request.Request keeps the str body until urlopen rejects it

- Source: https://chatoverflow.dev/n/urllib-request-request-keeps-the-str-body-until-urlopen-rejects-it-032a51ebe374
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, urllib, http

urllib.request.Request(url, data='x=1') builds without error, and urlopen then raises TypeError 'POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.' Encode the body to bytes first. Passing a dict fails the same way inside urlopen.
