updateStatusWithMedia not working #113

Closed
opened 2012-08-26 06:40:59 -07:00 by davidmann4 · 6 comments
davidmann4 commented 2012-08-26 06:40:59 -07:00 (Migrated from github.com)

updateStatusWithMedia still does not work for me ... (normal status update works great! )

  response = twitterImage.updateStatusWithMedia("C:\\Users\\Desktop\\python-twitter-0.8.2\\examples\\data\\1.png", status='thats me :)')
  File "build\bdist.win32\egg\twython\twython.py", line 445, in updateStatusWithMedia
  File "build\bdist.win32\egg\twython\twython.py", line 448, in _media_update
  File "build\bdist.win32\egg\twython\twython.py", line 233, in post
  File "build\bdist.win32\egg\twython\twython.py", line 225, in request
  File "build\bdist.win32\egg\twython\twython.py", line 206, in _request
ython.twython.TwythonError: u'Unauthorized: Authentication credentials were missing or incorrect. -- Could not authenticate you.'

any ideas ?

updateStatusWithMedia still does not work for me ... (normal status update works great! ) ``` python response = twitterImage.updateStatusWithMedia("C:\\Users\\Desktop\\python-twitter-0.8.2\\examples\\data\\1.png", status='thats me :)') File "build\bdist.win32\egg\twython\twython.py", line 445, in updateStatusWithMedia File "build\bdist.win32\egg\twython\twython.py", line 448, in _media_update File "build\bdist.win32\egg\twython\twython.py", line 233, in post File "build\bdist.win32\egg\twython\twython.py", line 225, in request File "build\bdist.win32\egg\twython\twython.py", line 206, in _request ython.twython.TwythonError: u'Unauthorized: Authentication credentials were missing or incorrect. -- Could not authenticate you.' ``` any ideas ?
y2rayk commented 2012-08-27 14:57:31 -07:00 (Migrated from github.com)

i had the same problem. as a workaround until this gets fixed try editing

requests/auth.py to something like this (i commented out 1 line and modified 1 line):

def __call__(self, r):
    """Add OAuth parameters to the request.

    Parameters may be included from the body if the content-type is
    urlencoded, if no content type is set an educated guess is made.
    """
    print "requests/auth.py call"
    contenttype = r.headers.get('Content-Type', None)
    # extract_params will not give params unless the body is a properly
    # formatted string, a dictionary or a list of 2-tuples.
    decoded_body = extract_params(r.data)

    _ct = (contenttype is None)
    _ct = _ct or contenttype.lower() == CONTENT_TYPE_FORM_URLENCODED

    #if _ct and decoded_body != None:
    if decoded_body != None: #MODIFIED HERE
        # extract_params can only check the present r.data and does not know
        # of r.files, thus an extra check is performed. We know that
        # if files are present the request will not have
        # Content-type: x-www-form-urlencoded. We guess it will have
        # a mimetype of multipart/form-encoded and if this is not the case
        # we assume the correct header will be set later.
        if r.files:
            # Omit body data in the signing and since it will always
            # be empty (cant add paras to body if multipart) and we wish
            # to preserve body.
            #r.headers['Content-Type'] = 'multipart/form-encoded'
            #^^^^^COMMENTED THAT OUT
            r.url, r.headers, _ = self.client.sign(
                unicode(r.full_url), unicode(r.method), None, r.headers)
i had the same problem. as a workaround until this gets fixed try editing requests/auth.py to something like this (i commented out 1 line and modified 1 line): ``` def __call__(self, r): """Add OAuth parameters to the request. Parameters may be included from the body if the content-type is urlencoded, if no content type is set an educated guess is made. """ print "requests/auth.py call" contenttype = r.headers.get('Content-Type', None) # extract_params will not give params unless the body is a properly # formatted string, a dictionary or a list of 2-tuples. decoded_body = extract_params(r.data) _ct = (contenttype is None) _ct = _ct or contenttype.lower() == CONTENT_TYPE_FORM_URLENCODED #if _ct and decoded_body != None: if decoded_body != None: #MODIFIED HERE # extract_params can only check the present r.data and does not know # of r.files, thus an extra check is performed. We know that # if files are present the request will not have # Content-type: x-www-form-urlencoded. We guess it will have # a mimetype of multipart/form-encoded and if this is not the case # we assume the correct header will be set later. if r.files: # Omit body data in the signing and since it will always # be empty (cant add paras to body if multipart) and we wish # to preserve body. #r.headers['Content-Type'] = 'multipart/form-encoded' #^^^^^COMMENTED THAT OUT r.url, r.headers, _ = self.client.sign( unicode(r.full_url), unicode(r.method), None, r.headers) ```
y2rayk commented 2012-08-30 06:50:57 -07:00 (Migrated from github.com)

sorry. dont use the above. use this workaround instead:

➜  twython git:(master) ✗ git diff twython/twython.py
diff --git a/twython/twython.py b/twython/twython.py
index 3adb6a6..3d9174f 100644
--- a/twython/twython.py
+++ b/twython/twython.py
@@ -170,6 +170,13 @@ class Twython(object):
         if method == 'get':
             response = func(url, params=params)
         else:
+            if files: # this is hack until the request lib is fixed
+                __, newheaders, _ = self.client.auth.client.sign(unicode(url), unicode(method), None, self.client.headers)
+                u_header = unicode('Authorization')
+                if u_header in newheaders:
+                    auth_header = newheaders[u_header].encode('utf-8')
+                    del newheaders[u_header]
+                    self.client.headers['Authorization'] = auth_header
             response = func(url, data=params, files=files)
         content = response.content.decode('utf-8')
sorry. dont use the above. use this workaround instead: ``` ➜ twython git:(master) ✗ git diff twython/twython.py diff --git a/twython/twython.py b/twython/twython.py index 3adb6a6..3d9174f 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -170,6 +170,13 @@ class Twython(object): if method == 'get': response = func(url, params=params) else: + if files: # this is hack until the request lib is fixed + __, newheaders, _ = self.client.auth.client.sign(unicode(url), unicode(method), None, self.client.headers) + u_header = unicode('Authorization') + if u_header in newheaders: + auth_header = newheaders[u_header].encode('utf-8') + del newheaders[u_header] + self.client.headers['Authorization'] = auth_header response = func(url, data=params, files=files) content = response.content.decode('utf-8') ```
davidmann4 commented 2012-08-30 06:56:43 -07:00 (Migrated from github.com)

but it worked for me ...
Am 30.08.2012 15:50 schrieb "y2rayk" notifications@github.com:

sorry. dont use the above. use this workaround instead:

➜ twython git:(master) ✗ git diff twython/twython.py
diff --git a/twython/twython.py b/twython/twython.py
index 3adb6a6 3adb6a6..3d9174f
100644
--- a/twython/twython.py
+++ b/twython/twython.py
@@ -170,6 +170,13 @@ class Twython(object):
if method == 'get':
response = func(url, params=params)
else:

  • if files: # this is hack until the request lib is fixed

  • __, newheaders, _ = self.client.auth.client.sign(unicode(url),
    unicode(method), None, self.client.headers)

  • u_header = unicode('Authorization')

  • if u_header in newheaders:

  • auth_header = newheaders[u_header].encode('utf-8')

  • del newheaders[u_header]

  • self.client.headers['Authorization'] = auth_header response =
    func(url, data=params, files=files) content =
    response.content.decode('utf-8')


    Reply to this email directly or view it on GitHubhttps://github.com/ryanmcgrath/twython/issues/113#issuecomment-8159953.

but it worked for me ... Am 30.08.2012 15:50 schrieb "y2rayk" notifications@github.com: > sorry. dont use the above. use this workaround instead: > > ➜ twython git:(master) ✗ git diff twython/twython.py > diff --git a/twython/twython.py b/twython/twython.py > index 3adb6a6 https://github.com/ryanmcgrath/twython/commit/3adb6a6..3d9174f > 100644 > --- a/twython/twython.py > +++ b/twython/twython.py > @@ -170,6 +170,13 @@ class Twython(object): > if method == 'get': > response = func(url, params=params) > else: > - if files: # this is hack until the request lib is fixed > - __, newheaders, _ = self.client.auth.client.sign(unicode(url), > unicode(method), None, self.client.headers) > - u_header = unicode('Authorization') > - if u_header in newheaders: > - auth_header = newheaders[u_header].encode('utf-8') > - del newheaders[u_header] > - self.client.headers['Authorization'] = auth_header response = > func(url, data=params, files=files) content = > response.content.decode('utf-8') > > — > Reply to this email directly or view it on GitHubhttps://github.com/ryanmcgrath/twython/issues/113#issuecomment-8159953.
y2rayk commented 2012-09-04 13:33:18 -07:00 (Migrated from github.com)

I upgraded to request 0.14 and updateStatusWithMedia works. ty for fixing

I upgraded to request 0.14 and updateStatusWithMedia works. ty for fixing
ryanmcgrath commented 2012-09-12 03:08:33 -07:00 (Migrated from github.com)

Closing this, as things should be alright now (thanks to @michaelhelmick for the tipoff).

Closing this, as things should be alright now (thanks to @michaelhelmick for the tipoff).
davidmann4 commented 2012-10-27 16:55:00 -07:00 (Migrated from github.com)

updated requests and now i have the error again ...

Update:

C:\Python27\Scripts>pip install twython
Downloading/unpacking twython
  Downloading twython-2.4.0.tar.gz
  Running setup.py egg_info for package twython

    warning: no files found matching '*' under directory 'examples'
    warning: no previously-included files matching '*.pyc' found under directory 'examples'
Requirement already satisfied (use --upgrade to upgrade): simplejson in c:\python27\lib\site-packages (from twython)
Downloading/unpacking requests>=0.13.9 (from twython)
  Downloading requests-0.14.2.tar.gz (361kB): 361kB downloaded
  Running setup.py egg_info for package requests

    warning: no files found matching 'tests\*.'
Installing collected packages: twython, requests
  Running setup.py install for twython

    warning: no files found matching '*' under directory 'examples'
    warning: no previously-included files matching '*.pyc' found under directory 'examples'
  Running setup.py install for requests

    warning: no files found matching 'tests\*.'
Successfully installed twython requests
Cleaning up...
updated requests and now i have the error again ... Update: ``` ruby C:\Python27\Scripts>pip install twython Downloading/unpacking twython Downloading twython-2.4.0.tar.gz Running setup.py egg_info for package twython warning: no files found matching '*' under directory 'examples' warning: no previously-included files matching '*.pyc' found under directory 'examples' Requirement already satisfied (use --upgrade to upgrade): simplejson in c:\python27\lib\site-packages (from twython) Downloading/unpacking requests>=0.13.9 (from twython) Downloading requests-0.14.2.tar.gz (361kB): 361kB downloaded Running setup.py egg_info for package requests warning: no files found matching 'tests\*.' Installing collected packages: twython, requests Running setup.py install for twython warning: no files found matching '*' under directory 'examples' warning: no previously-included files matching '*.pyc' found under directory 'examples' Running setup.py install for requests warning: no files found matching 'tests\*.' Successfully installed twython requests Cleaning up... ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#113
No description provided.