self.response_data = f.read()
else:
self.response_data = data
+ super(TwitterHTTPError, self).__init__(str(self))
def __str__(self):
fmt = ("." + self.format) if self.format else ""
def extend_call(arg):
return self.callable_cls(
auth=self.auth, format=self.format, domain=self.domain,
- callable_cls=self.callable_cls, timeout=self.timeout, uriparts=self.uriparts,
+ callable_cls=self.callable_cls, timeout=self.timeout,
secure=self.secure, gzip=self.gzip,
- (arg,))
+ uriparts=self.uriparts + (arg,))
if k == "_":
return extend_call
else:
uriBase = "http%s://%s/%s%s%s" %(
secure_str, self.domain, uri, dot, self.format)
+ # Catch media arguments to handle oauth query differently for multipart
+ media = None
+ for arg in ['media[]', 'banner', 'image']:
+ if arg in kwargs:
+ media = kwargs.pop(arg)
+ mediafield = arg
+ break
+
headers = {'Accept-Encoding': 'gzip'} if self.gzip else dict()
+ body = None; arg_data = None
if self.auth:
headers.update(self.auth.generate_headers())
- arg_data = self.auth.encode_params(uriBase, method, kwargs)
- if method == 'GET':
+ # Use urlencoded oauth args with no params when sending media
+ # via multipart and send it directly via uri even for post
+ arg_data = self.auth.encode_params(uriBase, method,
+ {} if media else kwargs )
+ if method == 'GET' or media:
uriBase += '?' + arg_data
- body = None
else:
body = arg_data.encode('utf8')
+ # Handle query as multipart when sending media
+ if media:
+ BOUNDARY = "###Python-Twitter###"
+ bod = []
+ bod.append('--' + BOUNDARY)
+ bod.append('Content-Disposition: form-data; name="%s"' %
+ mediafield)
+ bod.append('')
+ bod.append(media)
+ for k, v in kwargs.items():
+ bod.append('--' + BOUNDARY)
+ bod.append('Content-Disposition: form-data; name="%s"' % k)
+ bod.append('')
+ bod.append(v)
+ bod.append('--' + BOUNDARY + '--')
+ body = '\r\n'.join(bod)
+ headers['Content-Type'] = 'multipart/form-data; boundary=%s' % BOUNDARY
+
req = urllib_request.Request(uriBase, body, headers)
return self._handle_response(req, uri, arg_data, _timeout)
# Get your "home" timeline
t.statuses.home_timeline()
- # Get a particular friend's timeline
- t.statuses.friends_timeline(id="billybob")
-
- # Also supported (but totally weird)
- t.statuses.friends_timeline.billybob()
+ # Get a particular friend's tweets
+ t.statuses.user_timeline(user_id="billybob")
# Update your status
t.statuses.update(