gpt4 book ai didi

python - 尝试使用 remote_api 连接时获取 'Refreshing due to a 401'

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:35 25 4
gpt4 key购买 nike

我正在尝试连接到基于 https://cloud.google.com/appengine/docs/python/tools/remoteapi#enabling_remote_api_access_in_your_app 在 Google App Engine 上运行的生产数据存储区和 AppEngine - Remote API returning 401 and too-many-authGAE: remote_api and Application Default Credentials和其他人。

这是我连接到 Google App Engine Datastore 的代码

try:
import dev_appserver
dev_appserver.fix_sys_path()
except ImportError:
print('Please make sure the App Engine SDK is in your PYTHONPATH.')
raise

from google.appengine.ext.remote_api import remote_api_stub
import os

class RemoteApi:
@staticmethod
def use_remote_datastore():
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "my-appengine-default-service-account.json"
project_id = 'myapp'
project_address = '{}.appspot.com'.format(project_id)
RemoteApi.connect2(project_address)

@staticmethod
def auth_func2():
return ('myuser@myemail.com','mypassword')

@staticmethod
def connect2(project_address):
remote_api_stub.ConfigureRemoteApiForOAuth(
project_address,
'/_ah/remote_api', secure=True)

但是我得到了错误

NotSupportedOnThisPlatform

如果我再设置

secure=False

然后我得到

 INFO     2016-10-01 23:35:32,727 client.py:546] Attempting refresh to obtain initial access_token
....
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/dummy_thread.py", line 73, in allocate_lock
return LockType()
RuntimeError: maximum recursion depth exceeded

我试过运行

gcloud auth login

并创建一个新的服务帐户,这两个建议均在此处 AppEngine - Remote API returning 401 and too-many-auth

知道我做错了什么吗?

最佳答案

您提到了 auth_func2 但没有使用它,根据 remote_api 更新,每次使用 oauth 请求时没有此信息,连接是不可能的。

更改您的 connect2 方法并尝试这个 -

@staticmethod
def connect2(project_address):
remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', auth_func2, project_address)

P.S - 我假设您的 project_address 是正确的并且没有“http://”

关于python - 尝试使用 remote_api 连接时获取 'Refreshing due to a 401',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39812525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com