python-twitter-tools / twitter

Python Twitter API
http://mike.verdone.ca/twitter/
MIT License
3.18k stars 714 forks source link

Problem with security requests #383

Closed slink2111 closed 6 years ago

slink2111 commented 6 years ago

I see that my script, stuck here forever /usr/lib/python2.7/ssl.py:

 638                raise ValueError("Read on closed or unwrapped SSL socket.")
 639            try:
 640                if buffer is not None:
 641                    v = self._sslobj.read(len, buffer)
 642                else:
>643                    v = self._sslobj.read(len)
 644                return v
 645            except SSLError as x:
 646                if x.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs:
 647                    if buffer is not None:
 648                        return 0

the values of the vars are len = 8192 buffer = None

i call the api using the following code

api_version = '1.1'
    uriparts = ()
    if api_version:
        uriparts += (str(api_version),)

    auth = twitter.oauth.OAuth(oauth_token, oauth_token_secret, consumer_key, consumer_secret)
    t_api = twitter.api.TwitterCall(auth=auth, format="json", **timeout=15**, domain="api.twitter.com",
                                    callable_cls=twitter.api.TwitterCall, uriparts=uriparts)

and everything works till it stops. Now i haven't tried the execution by adding secure=False to the TwitterCall i will and i will give you new feedback.

boogheta commented 6 years ago

Why do you call it like this with internal functions? The proper use would rather be the simplier: t_api = twitter.Twitter(domain="api.twitter.com", api_version="1.1", format="json", auth=auth, secure=True) Is this because you want to tune the timeout argument?

slink2111 commented 6 years ago

This is exactly the case I need the timeout argument, because without it i see that my script hungs because the unlimited timeout (from default is set to None).

self._check_connected()
        timeout = self.gettimeout()
        try:
            if timeout == 0.0 and block:
                self.settimeout(None)
        >    self._sslobj.do_handshake()
        finally:
            self.settimeout(timeout) 

So with my code i avoid to get the TypeError: init() got an unexpected keyword argument 'timeout' when calling the api.

slink2111 commented 6 years ago

The execution with the argument secure=False isn't an option, it gives an SSL is required message and returns no data

RouxRC commented 6 years ago

I guess Twitter ended up forcing ssl connections making the option secure=False obsolete probably. To handle the timeout, you shouldn't need to call TwitterCall and can rather use the magic "_" prefixed arguments to use it with the regular calls as explained in the Readme and here: https://github.com/sixohsix/twitter/blob/master/twitter/api.py#L441-L447 For instance:

t_api = twitter.Twitter(domain="api.twitter.com", api_version="1.1", format="json", auth=auth, secure=True)
t_api.search.tweets(q="python", _timeout=15)
slink2111 commented 6 years ago

Thank you RouxRC i made some digging to the library and i found it my shelf. now my code seems to work like a charm there was no problem with the lib 🥇

RouxRC commented 6 years ago

all right, I'm closing this issue then, but feel free and reopen it or another if necessary!