apiclient.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:searchConsole 作者: get-data- 项目源码 文件源码
def makecall(self):
        # self.service is causing recursion error when left as class attribute #swap service to mock
        argv = []
        service, flags = sample_tools.init(
            argv, 'webmasters', 'v3', __doc__, __file__, parents=[], 
            scope='https://www.googleapis.com/auth/webmasters.readonly')
        try:
            if not self.clientquery['property_uri']:
                raise SystemExit('Unable to locate client URI for %s. Exiting.' % (self.clientquery['property_uri']))
            else:
                # response = self.service.searchanalytics().query(siteUrl=self.clientquery['property_uri'], body=self.request).execute() #swap response to mock
                response = service.searchanalytics().query(siteUrl=self.clientquery['property_uri'], body=self.request).execute() #swap response to mock
            return response
        except TypeError as error:
            raise SystemExit('There was an error in constructing the query : %s' % (error))
        except HttpError as error:
            # Handle API errors
            print('There was an API error : %s : %s' % (error.resp.status, error._get_reason()))
            response = [self.clientquery['query_date'],
                        self.clientquery['clientName'],
                        self.clientquery['siteMode'],
                        int(0),
                        'FALSE',
                        error.resp.status, 
                        error._get_reason()]
            return response
        except AccessTokenRefreshError:
            raise SystemExit('The credentials have been revoked or expired, please re-run the application to re-authorize')
        except Exception as e:
            raise SystemExit(e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号