Skip to content

Commit fcc0fae

Browse files
author
Will Trimble
committed
encode post data as unicode
1 parent 62785b7 commit fcc0fae

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

mglib/mglib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def body_from_url(url, accept, auth=None, data=None, debug=False, method=None):
7272

7373
# return python struct from JSON output of MG-RAST or Shock API
7474
def obj_from_url(url, auth=None, data=None, debug=False, method=None):
75+
if type(data) is str:
76+
data=data.encode("utf8")
7577
try:
7678
result = body_from_url(url, 'application/json', auth=auth, data=data, debug=debug, method=method)
7779
read = result.read()
@@ -100,7 +102,7 @@ def obj_from_url(url, auth=None, data=None, debug=False, method=None):
100102
sys.stderr.write("ERROR: %s\n" %obj['ERROR'])
101103
sys.exit(1)
102104
if ('error' in obj) and obj['error']:
103-
if isinstance(obj['error'], basestring):
105+
if isinstance(obj['error'], str):
104106
sys.stderr.write("ERROR:\n%s\n" %obj['error'])
105107
else:
106108
sys.stderr.write("ERROR: %s\n" %obj['error'][0])

0 commit comments

Comments
 (0)