Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

UnicodeDecodeError when using file-like objects with unicode name. #10

Merged
merged 3 commits into from

2 participants

@snoack

Currently you get a UnicodeDecodeError when using faces_detect() or faces_recognize() with a file-like object whose name attribute is a unicode object.

client = face_client.FaceClient(...)
client.faces_detect(file=open(u'...', 'r'))

That is fixed with 970457f, now. Furthermore I have cleaned up the code for file-like object support (42a66c7) and added a .gitignore file (da79177).

snoack added some commits
@snoack snoack Used consecutive instead of random filenames for anonymous files.
That way it is more robust against clashing file/field names and less code to maintain.
42a66c7
@snoack snoack Convert headers to str. Otherwise if some headers are given as unicod…
…e, it would

try to decode any other data in the mutlipart response when concatenating, which
will usually fail, as image data can't be decoded as ascii text.
970457f
@snoack snoack Added .gitignore file. da79177
@Kami Kami merged commit 5ff153b into Kami:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2011
  1. @snoack

    Used consecutive instead of random filenames for anonymous files.

    snoack authored
    That way it is more robust against clashing file/field names and less code to maintain.
  2. @snoack

    Convert headers to str. Otherwise if some headers are given as unicod…

    snoack authored
    …e, it would
    
    try to decode any other data in the mutlipart response when concatenating, which
    will usually fail, as image data can't be decoded as ascii text.
  3. @snoack

    Added .gitignore file.

    snoack authored
This page is out of date. Refresh to see the latest.
View
2  face_client/.gitignore
@@ -0,0 +1,2 @@
+*.py[co]
+.*.sw?
View
17 face_client/face_client.py
@@ -14,8 +14,6 @@
import os.path
import warnings
-from utils import get_random_string
-
try:
import json
except ImportError:
@@ -349,18 +347,17 @@ def send_request(self, method=None, parameters=None, files=None):
for key, value in data.iteritems():
form.field(key, value)
- for value in files:
- if hasattr(value, 'read'):
- if hasattr(value, 'name'):
- name = os.path.basename(value.name)
+ for i, file in enumerate(files, 1):
+ if hasattr(file, 'read'):
+ if hasattr(file, 'name'):
+ name = os.path.basename(file.name)
else:
- name = get_random_string(10)
+ name = 'attachment_%d' % i
close_file = False
- file = value
else:
- name = os.path.basename(value)
+ name = os.path.basename(file)
+ file = open(file, 'r')
close_file = True
- file = open(value, 'r')
try:
form.file(name, name, file.read())
View
2  face_client/multipart.py
@@ -74,7 +74,7 @@ def get(self):
lines = []
lines.append('--' + Part.BOUNDARY)
for (key, val) in self._headers.items():
- lines.append('%s: %s' % (key, val))
+ lines.append(str('%s: %s' % (key, val)))
lines.append('')
lines.append(self._body)
return lines
View
7 face_client/utils.py
@@ -1,7 +0,0 @@
-import random
-import string
-
-def get_random_string(length):
- value = ''.join(random.choice(string.letters + string.digits) for i in
- xrange(length))
- return value
Something went wrong with that request. Please try again.