I am using tweepy to extract all my friends friends and use the
following code for that:
13 def process(s):
14 l = len(s)
15 p = 0
16 for n in list(s):
17 p += 1
18 if not os.path.isfile(n+'.f'):
19 try:
20 print 'Processing %s (%s/%s)' % (n, p, l)
21 f = open(n+'.f', 'wb')
22 for user in tweepy.Cursor(tweepy.api.friends,
screen_name=n).items():
23 f.write(user.screen_name+'\n')
24 except (tweepy.TweepError, KeyboardInterrupt), e:
25 print str(e)
26 f.close()
27 os.rename(n+'.f', n+'.p')
28 break
29 else:
30 f.close()
I dump results for each user into a separate file. For some users, I
catch a "Not found" TweepError which I don't know how to handle. I'd
like to simply skip that user but wonder how.
Here's the unhandled stack trace of the above code when commenting
lines 24-30 out.
$ ./scanf.py friends.dat
Reading files.
Processing oliviertripet (40/267)
Traceback (most recent call last):
File "./scanf.py", line 57, in <module>
process(s)
File "./scanf.py", line 22, in process
for user in tweepy.Cursor(tweepy.api.friends, screen_name=n).items
():
File "build/bdist.cygwin-1.5.25-i686/egg/tweepy/cursor.py", line
109, in next
File "build/bdist.cygwin-1.5.25-i686/egg/tweepy/cursor.py", line 60,
in next
File "build/bdist.cygwin-1.5.25-i686/egg/tweepy/binder.py", line
167, in _call
tweepy.error.TweepError: Not found
Thanks in advance for any suggestion!
JP
Any ideas?
Sorry for the delayed response, been away during the holidays.
I am guessing you might have invalid screen names in your list "s" you
pass into process().
So when you go to page through the friends, twitter is sending a 404
not found response
back when the Cursor goes to fetch the first page of results. There is
no way to recover from this
since that user does not exist any more.
What you need to do is skip the screen name in the list and just go
onto the next one.
If the user does not exist there's no friends to be fetched, so it is
not recoverable.
Hope the helps you out.
Josh
All the best for 2010!!
JP
> > Any ideas?- Hide quoted text -
>
> - Show quoted text -
On Jan 4, 7:31 pm, Josh Roesslein <jroessl...@gmail.com> wrote: