iamvaibhavrai iamvaibhavrai -4 years ago 284
Python Question

How to pass an URL with whitespace in Python 3 urllib.request.urlopen() function?

Code Image

This is the simple program I am trying to run which shows error. If I pass URL without whitespace, then the program runs properly.

Error: 404 Bad Request.


If instead of "Hey You", I pass "Hey%20You". The program runs correctly.

Answer Source

You can pass the string to urllib.parse.quote to handle the escaping of special characters such as the space.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download