Code Monkey home page Code Monkey logo

tweepy's Introduction

Tweepy: Twitter for Python!

PyPI Version Python Versions DOI

Documentation Status Test Status Coverage Status

Discord Server

Installation

The easiest way to install the latest version from PyPI is by using pip:

pip install tweepy

To use the tweepy.asynchronous subpackage, be sure to install with the async extra:

pip install tweepy[async]

You can also use Git to clone the repository from GitHub to install the latest development version:

git clone https://github.com/tweepy/tweepy.git
cd tweepy
pip install .

Alternatively, install directly from the GitHub repository:

pip install git+https://github.com/tweepy/tweepy.git

Python 3.7 - 3.11 are supported.

Links

tweepy's People

Contributors

7kry avatar aaron1011 avatar achasveachas avatar dplefevre avatar drevicko avatar fitnr avatar fkropfhamer avatar foutoucour avatar groceryheist avatar harmon758 avatar hugovk avatar ifeve avatar inactivist avatar joshthecoder avatar keatonconrad avatar kk6 avatar kowalczyk-krzysztof avatar kumanna avatar lqhuang avatar mef51 avatar muraty avatar obskyr avatar okomestudio avatar pinkrabbit412 avatar robinhouston avatar shuuji3 avatar skoczen avatar tewalds avatar wjt avatar yeonghwansong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tweepy's Issues

rate limited calls to search api should use proper delay from Retry-After header

"An application that exceeds the rate limitations of the Search API will receive HTTP 420 response codes to requests. It is a best practice to watch for this error condition and honor the Retry-After header that instructs the application when it is safe to continue. The Retry-After header's value is the number of seconds your application should wait before submitting another query (for example: Retry-After: 67)."

--http://apiwiki.twitter.com/Rate-limiting

Patch gist: http://gist.github.com/373391

Doc issue: parameter for api.list_timeline should be "per_page", not "count"

The Tweepy doc shows the parameter for api.list_timeline() as "count":
http://joshthecoder.github.com/tweepy/docs/api.html#list-methods

However, the parameter according to Twitter's API shows "per_page":
http://apiwiki.twitter.com/Twitter-REST-API-Method:-GET-list-statuses

This appears simply to be a documentation error as the current Tweepy supports properly the per_page parameter:

$ cat test_list_timeline.py

import tweepy

list_timeline = tweepy.API().list_timeline('ev', 'randomlist', count=200)
print "api.list_timeline using count=200: %s" % len(list_timeline)

list_timeline = tweepy.API().list_timeline('ev', 'randomlist', per_page=200)
print "api.list_timeline using per_page=200: %s" % len(list_timeline)

$ python test_list_timeline.py

api.list_timeline using count=200: 20
api.list_timeline using per_page=200: 200

Cursor().limit(n) gives 'Cursor' object has no attribute 'limit'

The documentation for the Cursor tutorial:
http://joshthecoder.github.com/tweepy/docs/cursor_tutorial.html#limits
shows:

# Only iterate through the first 200 statuses
for status in Cursor(api.user_timeline).limit(200):
    process_status(status)

however, that throws an exception:
AttributeError: 'Cursor' object has no attribute 'limit'

>>> import tweepy
>>> api = tweepy.API()
>>> statuses = tweepy.Cursor(api.user_timeline).limit(200);
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Cursor' object has no attribute 'limit'

Without limit, works fine:

>>> statuses = tweepy.Cursor(api.user_timeline, screen_name='ev')
>>> status = statuses.items().next()
>>> status.text
'@xuanthu Saw Super Diamond...where?'

tweepy.error.TweepError: Failed to parse JSON payload: 'module' object has no attribute 'loads'

Hi,

the oauth dance worked, but i get this error on trying to send a tweet using the tutorial at http://jmillerinc.com/2010/05/31/twitter-from-the-command-line-in-python-using-oauth/

Traceback (most recent call last):
File "./twitter", line 15, in
api.update_status(sys.argv[1])
File "build/bdist.linux-i686/egg/tweepy/binder.py", line 181, in _call
File "build/bdist.linux-i686/egg/tweepy/binder.py", line 167, in execute
File "build/bdist.linux-i686/egg/tweepy/parsers.py", line 69, in parse
File "build/bdist.linux-i686/egg/tweepy/parsers.py", line 40, in parse
tweepy.error.TweepError: Failed to parse JSON payload: 'module' object has no attribute 'loads'

This happens on Debian 5.0.5 I have only little experience with Python, so I might have missed something obvious.

streaming.py crash

Downloaded streamwatcher.py from tweepy-examples. Sometimes, after a day of running, it crashes with the following (I commented out lines 117->119 in stremaing.py to catch the exception):

Traceback (most recent call last):
File "webapps/siti/mex/scripts/mystreamwatcher.py", line 68, in
myfunc()
File "webapps/siti/mex/scripts/mystreamwatcher.py", line 63, in myfunc
stream.filter(followed)
File "/home/user/webapps/siti/mex/scripts/tweepy/streaming.py", line 195, in filter
self._start(async)
File "/home/user/webapps/siti/mex/scripts/tweepy/streaming.py", line 160, in _start
self._run()
File "/home/user/webapps/siti/mex/scripts/tweepy/streaming.py", line 111, in _run
self._read_loop(resp)
File "/home/user/webapps/siti/mex/scripts/tweepy/streaming.py", line 140, in _read_loop
c = resp.read(1)
File "/usr/local/lib/python2.6/httplib.py", line 517, in read
return self._read_chunked(amt)
File "/usr/local/lib/python2.6/httplib.py", line 563, in _read_chunked
raise IncompleteRead(value)
httplib.IncompleteRead

Add structure to TweepError for better handling

Right now, TweepError only provides a string that describes the exception. This makes it difficult to write robust error handling code. For example, if there's a rate limit overage, I'd like to be able to handle that differently than a 404 (in the former, I want to retry, in the latter, give up). Right now, I check for rate limit errors by inspecting the error string, which is prone to breakage. It'd be great to have some better introspect into TweepErrors. If nothing else, the http status code of the response from Twitter would be a good start.

OAuthHandler' object has no attribute 'set_request_token'

On trying the GAE code sample, after the authorization happens, the error is produced. It goes like
"OAuthHandler' object has no attribute 'set_request_token'"

A detailed Server Log is provided herewith

WARNING 2009-09-30 15:04:51,874 urlfetch_stub.py:269] Stripped prohibited headers from URLFetch request: ['Host']
INFO 2009-09-30 15:04:52,836 dev_appserver.py:3034] "GET /oauth/ HTTP/1.1" 200 -
ERROR 2009-09-30 15:05:00,280 init.py:388] 'OAuthHandler' object has no attribute 'set_request_token'
Traceback (most recent call last):
File "/home/pranny/appengine/google/appengine/ext/webapp/init.py", line 507, in call
handler.get(*groups)
File "/home/pranny/appengine/projects/mbl2/oauth_example/handlers.py", line 58, in get
auth.set_request_token(request_token.token_key, request_token.token_secret)
AttributeError: 'OAuthHandler' object has no attribute 'set_request_token'
INFO 2009-09-30 15:05:00,307 dev_appserver.py:3034] "GET /oauth/callback?oauth_token=cbmnHe4Urqwdd3Le1l4rrFhap3nxKKYUu1cfhnJo8g&oauth_verifier=MTeAGy6NNYjaGjicbFKVjz9QJ63tEgtAAFmKuN8tXH0 HTTP/1.1" 200 -
INFO 2009-09-30 15:05:00,341 dev_appserver_index.py:212] Updating /home/pranny/appengine/projects/mbl2/index.yaml

'module' object has no attribute 'OAuthHandler'

when installing the latest tweepy (1.5 I think) with "python setup.py install" the error that OAuthHandler does not exist keeps popping up.

This seems to be resolved if you simply copy the dist/tweepy directory into dist-packages, which seems to indicate something goes wrong with install.

Each request decrease more than one hit on rate limit after changed to OAuth

I was using Basic Handler, but Twitter warned about OAuth becoming mandatory, so I've changed my code to use the OAuth handler. It looked fine at first, but my script started to crash with rate limits overpassed. I traced and debugged my script.

My script retrieves statuses from a list using tweepi.api.list_timeline, creates a list of these statuses using tweepy.Cursor method items() and shows some attributes from each tweepy.Status.

The problem is when I am getting these attributes like name, screen_name, there is new requests and my remaining_hits decreases.

I wasn't experiencing this kind of trouble when I was using Basic Authentication. There is any chance of slow connections need more than one request to fill the Status attributes? Even between apparently two consecutive api.rate_limit_status() there is reduction of remaining_hits.

Error in importing tweepy

In [1]: import tweepy

ImportError Traceback (most recent call last)

/tmp/ in ()

/usr/local/lib/python2.6/dist-packages/tweepy-1.3-py2.6.egg/tweepy/init.py in ()
12 from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResult, models
13 from tweepy.error import TweepError
---> 14 from tweepy.api import API
15 from tweepy.cache import Cache, MemoryCache, FileCache
16 from tweepy.auth import BasicAuthHandler, OAuthHandler

/usr/local/lib/python2.6/dist-packages/tweepy-1.3-py2.6.egg/tweepy/api.py in ()
6 import mimetypes
7
----> 8 from tweepy.binder import bind_api
9 from tweepy.error import TweepError
10 from tweepy.parsers import *

/usr/local/lib/python2.6/dist-packages/tweepy-1.3-py2.6.egg/tweepy/binder.py in ()
2 # Copyright 2009 Joshua Roesslein

  3 # See LICENSE

----> 4 import http.client
5 import urllib.request, urllib.parse, urllib.error
6 import time

ImportError: No module named http.client

BUG in send_direct_message()

Traceback (most recent call last):
File "<pyshell#8>", line 1, in
api.send_direct_message()
File "build\bdist.win32\egg\tweepy\binder.py", line 178, in _call
return method.execute()
File "build\bdist.win32\egg\tweepy\binder.py", line 161, in execute
raise TweepError(error_msg, resp)
TweepError: Invalid request.

locale

Took me about 30 minutes to figure out, tweepy is doing something wrong:

locale.setlocale(locale.LC_TIME, '') will not reset the locale. It will set it to the user's locale, which is not the default setting! 'C' is default.

IDLE and Windows Issue

ERROR message:
localTweet.tweetId = s.status.id
AttributeError: 'User' object has no attribute 'status'

I get this error after calling the api method

import tweepy
statuses = tweepy.api.friends(screen_name=twitusername)

that is not the bug..

I'm running in windows in idle.
When I go to run the code again I would expect the same error...
however I get this error

raise TweepError('Failed to send request: %s' % e)

TweepError: Failed to send request: timed out

When I restart idle I get the first error again.

Twitter returns unicode error messages for non-english users

When I set twitter account settings to Japanese language, twitter returns Japanese error messages. They are passed TweepError.init with 'reason' parameter. But Japanese strings are encoded in unicode, so str(reason) causes encoding errors.
It must be unicode(reason) for non-english languages.

lookup_users() returns an additional user "None"

send: 'GET /1/users/lookup.json?user_id=5307%2C691593%2C75933%2C1168301%2C3577531&screen_name=None

After being baffled as to why my input count and returned records never matched I did a bit of debugging and realized that if no screen_names were added to the query the url would be created with screen_name=None and the twitter user named "None" would be returned along with the results.

default search domain is incorrect, search() calls fail

By default, API objects use the search.twitter.com domain as their search domain, which causes all search() calls to throw errors with http response codes of 400. APIs created with twitter.com as their search_domain work correctly. twitter.com should be the default search domain, it seems.

Missing params for api.search()

The search() method is not allowing some parameters that twitter supports:
http://apiwiki.twitter.com/Twitter-Search-API-Method:-search

diff --git a/tweepy/api.py b/tweepy/api.py
index 27460e8..521470a 100644
--- a/tweepy/api.py
+++ b/tweepy/api.py
@@ -640,7 +640,7 @@ class API(object):
         search_api = True,
         path = '/search.json',
         payload_type = 'search_result', payload_list = True,
-        allowed_param = ['q', 'lang', 'locale', 'rpp', 'page', 'since_id', 'geocode', 'show_user']
+        allowed_param = ['q', 'lang', 'locale', 'rpp', 'page', 'since_id', 'geocode', 'show_user', 'max_id', 'since', 'until', 'result_type']
     )
     search.pagination_mode = 'page'

Store the raw json from twitter in the model objects

class Status(Model):

@classmethod
def parse(cls, api, json,rawjsonstring):
    self.originalJson = rawjsonstring

Please store the raw json returned from twitter as a field. I'd like a way to get the json that twitter returns to me unmodified. Particularly for the streaming api

Provide hook for setting a useragent

Twitter requests that you provide a custom useragent for API calls. It would be nice if there were a hook in Tweepy to let you set a useragent for the calls it makes.

Windows -- streaming dies due to unicode encoding exception

Under windows the streaming API seems to die after a while with this exception:
"'charmap' codec can't encode characters in position xxx-xxx: character maps to "

This seems to occur during the json parsing (streaming.py:133-143). I am not really sure
how to fix this issue. Maybe skip any lines that run into this error? If anyone can think of a better
solution please reply here. A patch would be much appreciated :)

Problem with time and locale

Reported by vensign on mailing list:

When I try to run my app with the LANG=es_VE.UTF8 I get the following
error:

File "/home/wako/Documentos/twclient/origami.py", line 37, in
checkuser
if not self.api.verify_credentials():
File "build/bdist.linux-x86_64/egg/tweepy/api.py", line 259, in
verify_credentials
File "build/bdist.linux-x86_64/egg/tweepy/binder.py", line 185, in
_call
File "build/bdist.linux-x86_64/egg/tweepy/binder.py", line 171, in
execute
File "build/bdist.linux-x86_64/egg/tweepy/parsers.py", line 73, in
parse
File "build/bdist.linux-x86_64/egg/tweepy/models.py", line 85, in
parse
File "build/bdist.linux-x86_64/egg/tweepy/models.py", line 50, in
parse
File "build/bdist.linux-x86_64/egg/tweepy/utils.py", line 14, in
parse_datetime
File "/usr/lib/python2.6/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.6/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'Mon Feb 01 18:45:13 +0000 2010' does not match
format '%a %b %d %H:%M:%S +0000 %Y'

After some tests I discover that the problem is the locale settings,
i.e. in my language %a = Mon will be %a=Lun.

If I set LANG=en_US.UTF-8 the problem go away.

So for now I put this line in my app code:
locale.setlocale(locale.LC_ALL, 'C')

And that fix the problem.

Is there anyway to fix this in the tweepy library?

Similar issue reported for python-twitter: http://code.google.com/p/python-twitter/issues/detail?id=10

Add request timeout argument to tweepy

In Python 2.6, both httplib.HTTPConnection and httplib.HTTPSConnection take the optional argument "timeout". Due to the (arguably broken) semantics of socket._GLOBAL_DEFAULT_TIMEOUT, there is no way to actually change the global default timeout. If Tweepy included the ability to pass through timeouts to the underlying object (as it already does for retry delays, etc.), it would definitely help tweepy handle intermittent network issues.

send_direct_message results in tweepy Error: Invalid Request

I'm using the tweepy library, 1.7 in a django project. I can retrieve mentions, send tweets, etc but I cannot seem to send a DM t anyone.

Trying it from the shell:
auth = tweepy.BasicAuthHanlder(username, pw)
api = tweepy.API(auth)
api.send_direct_message(targetusername, mesg)

results in the following:
177
178 method = APIMethod(api, args, kargs)
--> 179 return method.execute()
180
181

160                 except Exception:
161                     error_msg = "Twitter error response: status code = %s" % resp.status

--> 162 raise TweepError(error_msg, resp)
163
164 # Parse the response payload

tweepError: Invalid Request

Am I missing something?

oauth api.twitter.com causing 404's

Issue reported on twitter-dev mailing list by Josh Bleecher Snyder. Copy of email follows:

Hi all,

The tweepy twitter client uses api.twitter.com for the host for oauth calls:

REQUEST_TOKEN_URL = 'http://api.twitter.com/oauth/request_token'
AUTHORIZATION_URL = 'http://api.twitter.com/oauth/authorize'
AUTHENTICATE_URL = 'http://api.twitter.com/oauth/authenticate'
ACCESS_TOKEN_URL = 'http://api.twitter.com/oauth/access_token'

I've found that this works, until the user tries to sign out or sign
up during the authorization; if this happens, they get a 404. If,
however, twitter.com is used as the host:

REQUEST_TOKEN_URL = 'http://twitter.com/oauth/request_token'
AUTHORIZATION_URL = 'http://twitter.com/oauth/authorize'
AUTHENTICATE_URL = 'http://twitter.com/oauth/authenticate'
ACCESS_TOKEN_URL = 'http://twitter.com/oauth/access_token'

then everything, including signout and signup, works. This also
matches the instructions at
http://twitter.com/oauth_clients/details/%d.

However, it strikes me as odd that the oauth stuff half works at
api.twitter.com.

My question is: What is the bug? That the api.twitter.com oauth
endpoints only partially work -- in which case tweepy is fine and I
should file a bug with Twitter -- OR that the api.twitter.com oauth
works at all -- in which case I should ping the author of tweepy and
perhaps suggest to Twitter that they remove this partial functionality
to prevent future confusion?

Many thanks,
Josh

-----End of email------

On using "twitter.send_direct_message("user","hello")" I am getting this

Traceback (most recent call last):
File "<pyshell#36>", line 1, in
twitter.send_direct_message("user","hello")
File "build\bdist.win32\egg\tweepy\binder.py", line 178, in _call
return method.execute()
File "build\bdist.win32\egg\tweepy\binder.py", line 132, in execute
self.api.auth.apply_auth(
AttributeError: 'str' object has no attribute 'apply_auth'

Exception when call get_access_token

Exception: argument 2 to map() must support iteration

Code:
# Rebuild oauth handler
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_request_token(session.rtoken_key, session.rtoken_sec)

# Fetch access token
try:
    auth.get_access_token(request.vars.oauth_verifiler)
except tweepy.TweepError, e:
    return e # here

Twitter error response: status code = 301

I'm getting an unexpected 301 status code when using Tweepy on Python 2.5. A sample script is below along with the debugging traces:

import tweepy
tweepy.debug()
auth = tweepy.BasicAuthHandler(
    username='**insert username**',
    password='**insert password**'
)
api = tweepy.API(auth_handler=auth, secure=True)
try:
    api.update_status('It worked!')
except tweepy.TweepError , err:
    print err

Python 2.6.4 (Success):

send: 'POST /1/statuses/update.json?status=It+worked%21 HTTP/1.1\r\nHost: api.twitter.com\r\nAccept-Encoding: identity\r\nAuthorization: Basic QmV0aGFuZE1hcms6dHVnYm9hdA==\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Sun, 31 Jan 2010 02:13:22 GMT
header: Server: hi
header: X-Transaction: 1264904003-75143-25205
header: Status: 200 OK
header: ETag: "d9bd685d9cd197b6eca18646fa70c231"
header: Last-Modified: Sun, 31 Jan 2010 02:13:23 GMT
header: X-Runtime: 0.24167
header: Content-Type: application/json; charset=utf-8
header: Pragma: no-cache
header: Content-Length: 1139
header: Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
header: Expires: Tue, 31 Mar 1981 05:00:00 GMT
header: X-Revision: DEV
header: Set-Cookie: lang=en; path=/
header: Set-Cookie: _twitter_sess=BAh7CToMY3NyZl9pZCIlNDVkYTExYTYzOGJmNjk5ZTAzNjYzZjQ0ZTQyMWYw%250AMjk6EXRyYW5zX3Byb21wdDA6B2lkIiVkNGI1YThkZmRkYmEwN2VmNDg3YTk4%250AMzk2ZThlN2I1MyIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6%250AOkZsYXNoSGFzaHsABjoKQHVzZWR7AA%253D%253D--8eac8869e1a8d843326b301d30ecfb2e8de9f284; domain=.twitter.com; path=/
header: Vary: Accept-Encoding
header: Connection: close

Python 2.5.4 (Failure):

send: 'POST /1/statuses/update.json?status=It+worked%21 HTTP/1.1\r\nHost: api.twitter.com:443\r\nAccept-Encoding: identity\r\nAuthorization: Basic QmV0aGFuZE1hcms6dHVnYm9hdA==\r\n\r\n'
reply: 'HTTP/1.1 301 Moved Permanently\r\n'
header: Date: Sun, 31 Jan 2010 02:13:38 GMT
header: Server: Apache
header: Location: http://twitter.com/1/statuses/update.json?status=It+worked%2521
header: Cache-Control: max-age=300
header: Expires: Sun, 31 Jan 2010 02:18:38 GMT
header: Vary: Accept-Encoding
header: Content-Length: 271
header: Connection: close
header: Content-Type: text/html; charset=iso-8859-1
Twitter error response: status code = 301

It looks as though the port 443 is being added to api.twitter.com in Python 2.5 but I'm not sure why. Any help would be great. Thanks.

Errors after passing None to OAuthHandler set_access_token

OAuthHandler set_access_token() accepts None as key and secret arguments, but then later Tweepy api calls throw a TypeError.

I fixed my code so it won't pass a None anymore, but should Tweepy catch this first? i.e., set_access_token() fail if None is passed?

import tweepy

auth = tweepy.OAuthHandler('my consumer key', 'my consumer secret')
auth.set_access_token(None, None)
api = tweepy.API(auth)

assert api.verify_credentials()
Traceback (most recent call last):
  File "", line 1, in 
  File "tweepy/api.py", line 260, in verify_credentials
    )(self)
  File "tweepy/binder.py", line 138, in _call
    method, headers, parameters
  File "tweepy/auth.py", line 65, in apply_auth
    request.sign_request(self._sigmethod, self._consumer, self.access_token)
  File "tweepy/oauth.py", line 259, in sign_request
    self.build_signature(signature_method, consumer, token))
  File "tweepy/oauth.py", line 263, in build_signature
    return signature_method.build_signature(self, consumer, token)
  File "tweepy/oauth.py", line 626, in build_signature
    token)
  File "tweepy/oauth.py", line 619, in build_signature_base_string
    key += escape(token.secret)
  File "tweepy/oauth.py", line 50, in escape
    return urllib.quote(s, safe='~')
  File "/usr/lib/python2.6/urllib.py", line 1223, in quote
    res = map(safe_map.__getitem__, s)
TypeError: argument 2 to map() must support iteration

Infinite loop in streaming API

There is a "while True" loop that might infinitely loop in _read_loop if the response dies in the middle of the loop. The fix is to verify that the connection is still open and the stream is still running in that loop, rather than "while True." I'll send you a pull request with a fix soon.

send_direct_message is broken

It seems that the argument conversion is broken here, Twitter always returns 400 Bad Request, removing the check for multiple values on the same parameter in binder.py and then passing the screen_name or user_id per kwarg fixes it.

Patch in access to the OAuth rate limit status

Since the limit for OAuth requests is currently at 350 per hour and authenticated requests don't count against the normal rate_limit_status api, there should be a way to access the OAuth limit.

The information gets send with the header of every response on an authenticated call:
x-ratelimit-class = "api_identified"
x-ratelimit-limit = The current maximum of request per hour.
x-ratelimit-remaining = The requests remaining till the reset.
x-ratelimit-reset = UNIX timestamp as seconds when the next reset will occur.

I already patched this into api.py and binder.py:
http://github.com/BonsaiDen/tweepy/commit/cf0b4068e3e882498619d897d51462de91ca7e4e

May need some changes to the variable names, but besides that it should be OK I guess.

Endless loop when connection broken while in _read_loop in streaming.py

while reading the length of the length line the case when response return '' is not covered (I am not sure if the HTTPResponse is supposed to throw an Exception in this case so the bug might actually lie there). The result is a 100% CPU consumption and an endless loop.

I am using python 2.6 on OSX 10.6.1. The python version is from macports and tweepy version is 1.7.1.

The following modification would have the loop return whatever was read until that point. It allows the system to return an error and fail gracefully (and allow for recovery).

        # read length
        length = ''
        counter = 0
        while True:
            counter+=1
            c = resp.read(1)
            if c == '':
                break
            if c == '\n':
                break
            length += c
        length = length.strip()
        if length.isdigit():
            length = int(length)
        else:
            continue

Issue with install and import

I am relatively new to programming and am following a Head First book which has a send_to_twitter function that is deprecated. The forums pointed to the use of tweepy as a solution.
So I installed tweepy as per instructions (or at least I believe I did) yet I keep getting this error :

Traceback (most recent call last):
File "/Users/mikeyb/Documents/python_work/tweep.py", line 3, in 
import tweepy
ImportError: No module named tweepy

This is the result of the code:


#!/usr/bin/env python
 
import tweepy
 
CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'
 
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth_url = auth.get_authorization_url()
print 'Please authorize: ' + auth_url
verifier = raw_input('PIN: ').strip()
auth.get_access_token(verifier)
print "ACCESS_KEY = '%s'" % auth.access_token.key
print "ACCESS_SECRET = '%s'" % auth.access_token.secret

UnicodeEncodeError constructing TweepError

Still figuring out how to reproduce this, but seeing an encoding exception from w/in tweepy (while constructing a TweepError). Sample backtrace:

[UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 141: ordinal not in range(128)]
<snip/> api.create_friendship(followee_username, headers=USER_AGENT_HEADER)<snip/>
File "/usr/local/lib/python2.6/dist-packages/tweepy-1.5-py2.6.egg/tweepy/binder.py", line 167, in _call raise TweepError(error_msg)
File "/usr/local/lib/python2.6/dist-packages/tweepy-1.5-py2.6.egg/tweepy/error.py", line 9, in __init__    self.reason = str(reason)

Error: Basic authentication is not supported

I wrote this code:

at = tweepy.BasicAuthHandler('ebertti', 'mypass')
tw = tweepy.API(at)

but when I can this method:
tw.followers_ids(id='ebertti')

i get this error:

 tw.followers_ids(id='ebertti')
     File "C:\Python26\lib\site-packages\tweepy\binder.py", line 181, in _call
 return method.execute()
     File "C:\Python26\lib\site-packages\tweepy\binder.py", line 164, in execute
 raise TweepError(error_msg, resp)
 TweepError: [{u'message': u'Basic authentication is not supported', u'code': 53}]

but like 2h ago, every thing is working GREAT! But now, I have this problem...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.