Google cloud platform 通过谷歌应用程序引擎(只读文件系统)访问谷歌搜索控制台api

Google cloud platform 通过谷歌应用程序引擎(只读文件系统)访问谷歌搜索控制台api,google-cloud-platform,google-app-engine-python,google-search-console,Google Cloud Platform,Google App Engine Python,Google Search Console,当我在google应用程序引擎应用程序中使用oauth2client.file.storage.get()时,它返回IOError(errno.EROFS,“只读文件系统”,filename)。日志堆栈如下所示: File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\main.py", line 291, in main run_wsgi_app(app) File "C:\Users\john\AppData\Local

当我在google应用程序引擎应用程序中使用oauth2client.file.storage.get()时,它返回IOError(errno.EROFS,“只读文件系统”,filename)。日志堆栈如下所示:

File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\main.py", line 291, in main
run_wsgi_app(app)
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\webapp\util.py", line 101, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\webapp\util.py", line 119, in run_bare_wsgi_app
result = application(env, _start_response)
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__
return handler.dispatch()
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\main.py", line 216, in get
response = service.searchanalytics().query(siteUrl=property_uri, body=request).execute()
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\googleapiclient\http.py", line 836, in execute
method=str(self.method), body=self.body, headers=self.headers)
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\googleapiclient\http.py", line 167, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\oauth2client\transport.py", line 186, in new_request
credentials._refresh(orig_request_method)
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\oauth2client\client.py", line 761, in _refresh
self._do_refresh_request(http)
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\oauth2client\client.py", line 802, in _do_refresh_request
self.store.locked_put(self)
File "c:\Users\john\AppData\Local\Google\Cloud SDK\gsc2gbq-test\oauth2client\file.py", line 85, in locked_put
f = open(self._filename, 'w')
File "C:\Users\john\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\stubs.py", line 278, in __init__
raise IOError(errno.EROFS, 'Read-only file system', filename) IOError: [Errno 30] Read-only file system: './webmaster_credentials.dat'
为了访问Google搜索控制台API,我使用以下代码对Google搜索控制台API进行身份验证和访问。我认为这是问题的原因

# Prepare the API service
    from oauth2client.file import Storage

    storage = Storage("webmaster_credentials.dat")
    credentials = storage.locked_get()

    http_auth = httplib2.Http()
    http_auth = credentials.authorize(http_auth)
    service = build('webmasters', 'v3', http=http_auth, cache_discovery=False)
我对此做了一些研究。一些聪明人指出,这是因为谷歌应用程序引擎是只读系统

我的问题是:如何在谷歌应用程序引擎中访问谷歌搜索控制台API,以及如何解决这个问题:IOError(errno.EROFS,“只读文件系统”,filename)。


感谢您的回复或评论。

我自己的问题已经解决了。所以我把我的解决方案贴在这里,希望它能在你读到这篇文章时对你有所帮助

问题是必须刷新凭证文件的短期有效令牌,因此必须将新令牌写入google app engine上的凭证文件

我无法使用以下方法完成此操作:

from oauth2client.file import Storage

storage = Storage("webmaster_credentials.dat")
credentials = storage.locked_get()
相反,使用以下身份验证方法一次性解决了我的问题:p

from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials(access_token=access_token, client_id=client_id, client_secret=client_secret,
                                    refresh_token=refresh_token, token_expiry=token_expiry, token_uri=token_uri, user_agent=user_agent, revoke_uri=revoke_uri)
您只需要使用来自google app engine或其他google API的凭据定义变量

祝你好运,快乐