Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
4fd1096d
Commit
4fd1096d
authored
Aug 18, 2009
by
Josh Roesslein
Browse files
Fix issues with update profile images causing 500 error.
parent
1e6485cd
Changes
3
Hide whitespace changes
Inline
Side-by-side
ROADMAP
View file @
4fd1096d
...
...
@@ -7,7 +7,6 @@ The plan of attack for the next version of Tweepy.
+ prepare for social graph changes mentioned on mailinglist
+ finish search api
+ autodetect authenticated user's ID [DONE]
+ timeline paging
Future...
=========
...
...
tweepy/api.py
View file @
4fd1096d
...
...
@@ -247,22 +247,24 @@ class API(object):
"""Update profile image"""
def
update_profile_image
(
self
,
filename
):
headers
,
post_data
=
_pack_image
(
filename
,
700
)
bind_api
(
path
=
'/account/update_profile_image.json'
,
method
=
'POST'
,
parser
=
parse_none
,
require_auth
=
True
)(
self
,
post_data
=
_pack_image
(
filename
,
700
)
)
)(
self
,
post_data
=
post_data
,
headers
=
headers
)
"""Update profile background image"""
def
update_profile_background_image
(
self
,
filename
,
*
args
,
**
kargs
):
headers
,
post_data
=
_pack_image
(
filename
,
800
)
bind_api
(
path
=
'/account/update_profile_background_image.json'
,
method
=
'POST'
,
parser
=
parse_none
,
allowed_param
=
[
'tile'
],
require_auth
=
True
)(
self
,
post_data
=
_pack_image
(
filename
,
800
)
)
)(
self
,
post_data
=
post_data
,
headers
=
headers
)
"""Update profile"""
update_profile
=
bind_api
(
...
...
@@ -438,7 +440,7 @@ def _pack_image(filename, max_size):
# build the mulitpart-formdata body
fp
=
open
(
filename
,
'rb'
)
BOUNDARY
=
'
--
Tw3ePy'
BOUNDARY
=
'Tw3ePy'
body
=
[]
body
.
append
(
'--'
+
BOUNDARY
)
body
.
append
(
'Content-Disposition: form-data; name="image"; filename="%s"'
%
filename
)
...
...
@@ -448,6 +450,13 @@ def _pack_image(filename, max_size):
body
.
append
(
'--'
+
BOUNDARY
+
'--'
)
body
.
append
(
''
)
fp
.
close
()
body
=
'
\r\n
'
.
join
(
body
)
return
'
\r\n
'
.
join
(
body
)
# build headers
headers
=
{
'Content-Type'
:
'multipart/form-data; boundary=Tw3ePy'
,
'Content-Length'
:
len
(
body
)
}
return
headers
,
body
tweepy/binder.py
View file @
4fd1096d
...
...
@@ -23,6 +23,13 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
else
:
post_data
=
None
# check for headers
if
'headers'
in
kargs
:
headers
=
dict
(
kargs
[
'headers'
])
del
kargs
[
'headers'
]
else
:
headers
=
{}
# build parameter dict
if
allowed_param
:
parameters
=
{}
...
...
@@ -42,11 +49,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
raise
TweepError
(
'This method takes no parameters!'
)
parameters
=
None
# Assemble headers
headers
=
{
'User-Agent'
:
'tweepy'
}
# Build url with parameters
if
parameters
:
url
=
'%s?%s'
%
(
api
.
api_root
+
path
,
urllib
.
urlencode
(
parameters
))
...
...
@@ -79,7 +81,7 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
conn
=
httplib
.
HTTPConnection
(
_host
,
timeout
=
10.0
)
# Build request
conn
.
request
(
method
,
url
,
headers
=
headers
)
conn
.
request
(
method
,
url
,
headers
=
headers
,
body
=
post_data
)
# Get response
resp
=
conn
.
getresponse
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment