Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#! /usr/bin/env python
This code works with Python 2.6 but fails on Python 2.7
import httplib, urllib2
params = b'\x40\x00\x01\x02\xFF'
url = unicode("")
req = urllib2.Request(url, data=params)
Copy link

Workaround for this issue:

byte_params = bytearray(params)
req = urllib2.Request(url, data=byte_params)

Copy link

zed commented Feb 9, 2012

url can't contain non-ascii characters that are not percent-encoded (rfc3986) therefore the correct fix is to never use unicode for urls. In this case url = url.encode('ascii') is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment