当前位置: 首页>>代码示例>>Python>>正文


Python error.TweepError方法代码示例

本文整理汇总了Python中tweepy.error.TweepError方法的典型用法代码示例。如果您正苦于以下问题:Python error.TweepError方法的具体用法?Python error.TweepError怎么用?Python error.TweepError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tweepy.error的用法示例。


在下文中一共展示了error.TweepError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_authorization_url

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def get_authorization_url(self, signin_with_twitter=False):
        """Get the authorization URL to redirect the user"""
        try:
            # get the request token
            self.request_token = self._get_request_token()

            # build auth request and return as url
            if signin_with_twitter:
                url = self._get_oauth_url('authenticate')
            else:
                url = self._get_oauth_url('authorize')
            request = oauth.OAuthRequest.from_token_and_callback(
                token=self.request_token, http_url=url
            )

            return request.to_url()
        except Exception, e:
            raise TweepError(e) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:20,代码来源:auth.py

示例2: get_access_token

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def get_access_token(self, verifier=None):
        """
        After user has authorized the request token, get access token
        with user supplied verifier.
        """
        try:
            url = self._get_oauth_url('access_token')

            # build request
            request = oauth.OAuthRequest.from_consumer_and_token(
                self._consumer,
                token=self.request_token, http_url=url,
                verifier=str(verifier)
            )
            request.sign_request(self._sigmethod, self._consumer, self.request_token)

            # send request
            resp = urlopen(Request(url, headers=request.to_header()))
            self.access_token = oauth.OAuthToken.from_string(resp.read())
            return self.access_token
        except Exception, e:
            raise TweepError(e) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:24,代码来源:auth.py

示例3: get_xauth_access_token

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def get_xauth_access_token(self, username, password):
        """
        Get an access token from an username and password combination.
        In order to get this working you need to create an app at
        http://twitter.com/apps, after that send a mail to api@twitter.com
        and request activation of xAuth for it.
        """
        try:
            url = self._get_oauth_url('access_token', secure=True) # must use HTTPS
            request = oauth.OAuthRequest.from_consumer_and_token(
                oauth_consumer=self._consumer,
                http_method='POST', http_url=url,
                parameters = {
                    'x_auth_mode': 'client_auth',
                    'x_auth_username': username,
                    'x_auth_password': password
                }
            )
            request.sign_request(self._sigmethod, self._consumer, None)

            resp = urlopen(Request(url, data=request.to_postdata()))
            self.access_token = oauth.OAuthToken.from_string(resp.read())
            return self.access_token
        except Exception, e:
            raise TweepError(e) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:27,代码来源:auth.py

示例4: parse

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def parse(self, method, payload):
        try:
            if method.payload_type is None: return
            model = getattr(self.model_factory, method.payload_type)
        except AttributeError:
            raise TweepError('No model for this payload type: %s' % method.payload_type)

        json = JSONParser.parse(self, method, payload)
        if isinstance(json, tuple):
            json, cursors = json
        else:
            cursors = None

        if method.payload_list:
            result = model.parse_list(method.api, json)
        else:
            result = model.parse(method.api, json)

        if cursors:
            return result, cursors
        else:
            return result 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:24,代码来源:parsers.py

示例5: media_upload

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def media_upload(self, filename, *args, **kwargs):
        """ :reference: https://dev.twitter.com/rest/reference/post/media/upload
            :reference https://dev.twitter.com/rest/reference/post/media/upload-chunked
            :allowed_param:
        """
        f = kwargs.pop('file', None)

        mime, _ = mimetypes.guess_type(filename)
        size = getfilesize(filename, f)

        if mime in IMAGE_MIMETYPES and size < self.max_size_standard:
            return self.image_upload(filename, file=f, *args, **kwargs)

        elif mime in CHUNKED_MIMETYPES:
            return self.upload_chunked(filename, file=f, *args, **kwargs)

        else:
            raise TweepError("Can't upload media with mime type %s" % mime) 
开发者ID:fitnr,项目名称:twitter_bot_utils,代码行数:20,代码来源:api.py

示例6: cmd_verify

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def cmd_verify(bot, update, args, chat):
    if not chat.twitter_request_token:
        bot.reply(update, "Use /auth command first")
        return
    if len(args) < 1:
        bot.reply(update, "No verifier code specified")
        return
    verifier_code = args[0]
    auth = OAuthHandler(bot.tw.auth.consumer_key, bot.tw.auth.consumer_secret)
    auth.request_token = json.loads(chat.twitter_request_token)
    try:
        auth.get_access_token(verifier_code)
    except TweepError:
        bot.reply(update, "Invalid verifier code. Use /auth again")
        return
    chat.twitter_token = auth.access_token
    chat.twitter_secret = auth.access_token_secret
    chat.save()
    bot.reply(update, "Access token setup complete")
    api = tweepy.API(auth)
    settings = api.get_settings()
    tz_name = settings.get("time_zone", {}).get("tzinfo_name")
    cmd_set_timezone(bot, update, [tz_name]) 
开发者ID:franciscod,项目名称:telegram-twitter-forwarder-bot,代码行数:25,代码来源:commands.py

示例7: get_access_token

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def get_access_token(self, verifier=None):
        """
        After user has authorized the request token, get access token
        with user supplied verifier.
        """
        try:
            url = self._get_oauth_url('access_token')
            self.oauth = OAuth1Session(self.consumer_key,
                                       client_secret=self.consumer_secret,
                                       resource_owner_key=self.request_token['oauth_token'],
                                       resource_owner_secret=self.request_token['oauth_token_secret'],
                                       verifier=verifier, callback_uri=self.callback)
            resp = self.oauth.fetch_access_token(url)
            self.access_token = resp['oauth_token']
            self.access_token_secret = resp['oauth_token_secret']
            return self.access_token, self.access_token_secret
        except Exception as e:
            raise TweepError(e) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:20,代码来源:auth.py

示例8: get_xauth_access_token

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def get_xauth_access_token(self, username, password):
        """
        Get an access token from an username and password combination.
        In order to get this working you need to create an app at
        http://twitter.com/apps, after that send a mail to api@twitter.com
        and request activation of xAuth for it.
        """
        try:
            url = self._get_oauth_url('access_token')
            oauth = OAuth1(self.consumer_key,
                           client_secret=self.consumer_secret)
            r = requests.post(url=url,
                              auth=oauth,
                              headers={'x_auth_mode': 'client_auth',
                                       'x_auth_username': username,
                                       'x_auth_password': password})

            credentials = parse_qs(r.content)
            return credentials.get('oauth_token')[0], credentials.get('oauth_token_secret')[0]
        except Exception as e:
            raise TweepError(e) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:23,代码来源:auth.py

示例9: parse

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def parse(self, method, payload):
        try:
            if method.payload_type is None:
                return
            model = getattr(self.model_factory, method.payload_type)
        except AttributeError:
            raise TweepError('No model for this payload type: '
                             '%s' % method.payload_type)

        json = JSONParser.parse(self, method, payload)
        if isinstance(json, tuple):
            json, cursors = json
        else:
            cursors = None

        if method.payload_list:
            result = model.parse_list(method.api, json)
        else:
            result = model.parse(method.api, json)

        if cursors:
            return result, cursors
        else:
            return result 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:26,代码来源:parsers.py

示例10: _get_request_token

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def _get_request_token(self):
        try:
            url = self._get_oauth_url('request_token')
            request = oauth.OAuthRequest.from_consumer_and_token(
                self._consumer, http_url=url, callback=self.callback
            )
            request.sign_request(self._sigmethod, self._consumer, None)
            resp = urlopen(Request(url, headers=request.to_header()))
            return oauth.OAuthToken.from_string(resp.read())
        except Exception, e:
            raise TweepError(e) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:13,代码来源:auth.py

示例11: get_username

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def get_username(self):
        if self.username is None:
            api = API(self)
            user = api.verify_credentials()
            if user:
                self.username = user.screen_name
            else:
                raise TweepError("Unable to get username, invalid oauth token!")
        return self.username 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:11,代码来源:auth.py

示例12: prev

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def prev(self):
        if self.prev_cursor == 0:
            raise TweepError('Can not page back more, at first page')
        data, self.next_cursor, self.prev_cursor = self.method(
                cursor=self.prev_cursor, *self.args, **self.kargs
        )
        self.count -= 1
        return data 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:10,代码来源:cursor.py

示例13: verify_credentials

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def verify_credentials(self, **kargs):
        try:
            return bind_api(
                path = '/account/verify_credentials.json',
                payload_type = 'user',
                require_auth = True,
                allowed_param = ['include_entities', 'skip_status'],
            )(self, **kargs)
        except TweepError, e:
            if e.response and e.response.status == 401:
                return False
            raise 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:14,代码来源:api.py

示例14: _pack_image

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def _pack_image(filename, max_size, form_field="image"):
        """Pack image from file into multipart-formdata post body"""
        # image must be less than 700kb in size
        try:
            if os.path.getsize(filename) > (max_size * 1024):
                raise TweepError('File is too big, must be less than 700kb.')
        except os.error:
            raise TweepError('Unable to access file')

        # image must be gif, jpeg, or png
        file_type = mimetypes.guess_type(filename)
        if file_type is None:
            raise TweepError('Could not determine file type')
        file_type = file_type[0]
        if file_type not in ['image/gif', 'image/jpeg', 'image/png']:
            raise TweepError('Invalid file type for image: %s' % file_type)

        # build the mulitpart-formdata body
        fp = open(filename, 'rb')
        BOUNDARY = 'Tw3ePy'
        body = []
        body.append('--' + BOUNDARY)
        body.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (form_field, filename))
        body.append('Content-Type: %s' % file_type)
        body.append('')
        body.append(fp.read())
        body.append('--' + BOUNDARY + '--')
        body.append('')
        fp.close()
        body = '\r\n'.join(body)

        # build headers
        headers = {
            'Content-Type': 'multipart/form-data; boundary=Tw3ePy',
            'Content-Length': str(len(body))
        }

        return headers, body 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:40,代码来源:api.py

示例15: fave_mentions

# 需要导入模块: from tweepy import error [as 别名]
# 或者: from tweepy.error import TweepError [as 别名]
def fave_mentions(api, dry_run=None):
    '''
    Fave (aka like) recent mentions from user authenicated in 'api'.
    :api twitter_bot_utils.api.API
    :dry_run bool don't actually favorite, just report
    '''
    f = api.favorites(include_entities=False, count=150)
    favs = [m.id_str for m in f]

    try:
        mentions = api.mentions_timeline(trim_user=True, include_entities=False, count=75)
    except Exception as e:
        raise e

    for mention in mentions:
        # only try to fav if not in recent favs
        if mention.id_str not in favs:
            try:
                api.logger.info('liking %s: %s', mention.id_str, mention.text)

                if not dry_run:
                    api.create_favorite(mention.id_str, include_entities=False)

            except RateLimitError:
                api.logger.warning("reached Twitter's rate limit, sleeping for %d minutes", RATE_LIMIT_RESET_MINUTES)
                sleep(RATE_LIMIT_RESET_MINUTES * 60)
                api.create_favorite(mention.id_str, include_entities=False)

            except TweepError as e:
                api.logger.error('error liking %s', mention.id_str)
                api.logger.error("code %s: %s", e.api_code, e) 
开发者ID:fitnr,项目名称:twitter_bot_utils,代码行数:33,代码来源:tools.py


注:本文中的tweepy.error.TweepError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。