Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnicodeDecodeError for httplib #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions txclib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ def make_request(method, host, url, username, password, fields=None,
num_pools = 1
managers = {}

try:
# Compatibility with python2 and python3
unicode_comp = unicode
except NameError:
unicode_comp = str

if isinstance(host, unicode_comp):
host = host.encode('UTF-8')
if isinstance(url, unicode_comp):
url = url.encode('UTF-8')

if host.lower().startswith("http://"):
scheme = "http"
if "http_proxy" in os.environ:
Expand Down Expand Up @@ -183,7 +194,7 @@ def make_request(method, host, url, username, password, fields=None,
def get_details(api_call, username, password, *args, **kwargs):
"""
Get the tx project info through the API.

This function can also be used to check the existence of a project.
"""
url = API_URLS[api_call] % kwargs
Expand All @@ -200,7 +211,7 @@ def get_details(api_call, username, password, *args, **kwargs):
def valid_slug(slug):
"""
Check if a slug contains only valid characters.

Valid chars include [-_\w]
"""
try:
Expand Down Expand Up @@ -258,7 +269,7 @@ def mkdir_p(path):
def confirm(prompt='Continue?', default=True):
"""
Prompt the user for a Yes/No answer.

Args:
prompt: The text displayed to the user ([Y/n] will be appended)
default: If the default value will be yes or no
Expand Down Expand Up @@ -294,7 +305,7 @@ def color_text(text, color_name, bold=False):
This command can be used to colorify command line output. If the shell
doesn't support this or the --disable-colors options has been set, it just
returns the plain text.

Usage:
print "%s" % color_text("This text is red", "RED")
"""
Expand All @@ -308,7 +319,7 @@ def color_text(text, color_name, bold=False):
def files_in_project(curpath):
"""
Iterate over the files in the project.

Return each file under ``curpath`` with its absolute name.
"""
visited = set()
Expand Down