lastlegion / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

Expetion with encoding #103

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use my script at
http://metal3d.org/index.php/blog/ticket/2009/11/06/Twitter-client-terminal
2. run python script.py
3. wait 3 minutes (3*60 sleeping time)

What is the expected output? What do you see instead?
No error

What version of the product are you using? On what operating system?
last from fedora

Please provide any additional information below.

Using my code you can see here:
http://metal3d.org/index.php/blog/ticket/2009/11/06/Twitter-client-terminal

I set input_encoding to utf-8. While reading twitts, this error appears:
Traceback (most recent call last):
  File "bin/screentwitt.py", line 49, in <module>
    app.GetTwitts();
  File "bin/screentwitt.py", line 16, in GetTwitts
    statues = self.__api.GetFriendsTimeline(since_id=last_id)
  File "/usr/lib/python2.6/site-packages/twitter.py", line 1371, in
GetFriendsTimeline
    json = self._FetchUrl(url, parameters=parameters)
  File "/usr/lib/python2.6/site-packages/twitter.py", line 2009, in _FetchUrl
    url = self._BuildUrl(url, extra_params=extra_params)
  File "/usr/lib/python2.6/site-packages/twitter.py", line 1883, in _BuildUrl
    extra_query = self._EncodeParameters(extra_params)
  File "/usr/lib/python2.6/site-packages/twitter.py", line 1949, in
_EncodeParameters
    return urllib.urlencode(dict([(k, self._Encode(v)) for k, v in
parameters.items() if v is not None]))
  File "/usr/lib/python2.6/site-packages/twitter.py", line 1930, in _Encode
    return unicode(s, self._input_encoding).encode('utf-8')
TypeError: coercing to Unicode: need string or buffer, int found

This is not everytime... only the second time I use
GetFriendsTimeline(status_id)... 

Original issue reported on code.google.com by Metal3d on 6 Nov 2009 at 3:39

GoogleCodeExporter commented 9 years ago
Same with 60 second sleep, 50 seconds... etc... only to say that's not a session
problem :)

Original comment by Metal3d on 6 Nov 2009 at 3:42

GoogleCodeExporter commented 9 years ago
mmmm maybe I found what's append.
I changed:
 last_id=s.id
by
 last_id=str(s.id)

I suppose that GetFriendsTimeline() takes status_id as string and not as int. 
Script
is running for 40 minutes, no crash !

Are you ok with this ?

Original comment by Metal3d on 6 Nov 2009 at 4:02

GoogleCodeExporter commented 9 years ago
In hindsight, I should probably have made user.id a string. In the dev branch 
(which 
defines those with protocol buffers) it's actually a uint64.

But yes, casting that to a str in your code should be fine.

Original comment by dclinton on 6 Nov 2009 at 4:09

GoogleCodeExporter commented 9 years ago
It's not really user.id but status.id, in fact I get status from the last I get 
in
first iteration.

It's ok, I did modifications and it works fine. Thanks.

You can close this bug report I think :)

Original comment by Metal3d on 6 Nov 2009 at 4:23