Skip to content

Instantly share code, notes, and snippets.

@ssbarnea
Created June 26, 2011 11:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssbarnea/1047551 to your computer and use it in GitHub Desktop.
Save ssbarnea/1047551 to your computer and use it in GitHub Desktop.
python-bug-12398
#! /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("http://posttestserver.com/post.php")
req = urllib2.Request(url, data=params)
urllib2.urlopen(req)
@zed
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