Google App Engine中微服务之间的通信

huangapple go评论82阅读模式
英文:

Communication between Microservices in Google App Engine

问题

我目前在Google App Engine中有5种不同的服务,它们都在FastAPI Python标准环境中运行。当调用一个服务时,它们会调用授权服务,如果权限有效则继续执行。我使用防火墙规则禁用所有传入请求,但允许我的计算机。当使用防火墙规则时,我无法调用其他服务,因为它返回"Access Forbidden"。后来我发现了有关在GAE中使用Python中的请求的内容,需要使用Google的URLfetch来调用其他服务。但当我使用requests_toolbelt.adapters.appengine中的monkeypatch()函数时,在App Engine中出现错误:

  File "/layers/google.python.pip/pip/lib/python3.10/site-packages/requests_toolbelt/adapters/appengine.py", line 121, in __init__
    self.appengine_manager = gaecontrib.AppEngineManager(
  File "/layers/google.python.pip/pip/lib/python3.10/site-packages/urllib3/contrib/appengine.py", line 107, in __init__
    raise AppEnginePlatformError(
urllib3.contrib.appengine.AppEnginePlatformError: URLFetch在此环境中不可用

限制API的主要原因是没有人能够阅读服务的文档

<details>
<summary>英文:</summary>

I have currently 5 different services in Google App Engine all of them are in FastAPI Python standard environment. When a service gets called they call an authorization service and continue if permissions are valid. Im using firewall rule to disable all incoming requests but allow my computer. When using the firewall rule I cannot call the other service because it return Access Forbidden. I then found something about the requests in Python in GAE that you have to use Google&#39;s URLfetch to make calls to other services. But when I use the `monkeypatch()` function from `requests_toolbelt.adapters.appengine` I recieve an error in App Engine 
```python3
  File &quot;/layers/google.python.pip/pip/lib/python3.10/site-packages/requests_toolbelt/adapters/appengine.py&quot;, line 121, in __init__
    self.appengine_manager = gaecontrib.AppEngineManager(
  File &quot;/layers/google.python.pip/pip/lib/python3.10/site-packages/urllib3/contrib/appengine.py&quot;, line 107, in __init__
    raise AppEnginePlatformError(
urllib3.contrib.appengine.AppEnginePlatformError: URLFetch is not available in this environment.

The main reason to restrict the API's is that nobody is able to read the docs from the services.

答案1

得分: 1

正如在这个文档中提到的,Python 3运行时不需要中间服务来处理出站请求。如果您想迁移不再使用URL Fetch API但仍需要类似功能的请求,您应该将这些请求迁移到使用标准的Python库,例如requests库。

正如在这个线程中讨论的,似乎您也面临着类似的问题。

> 项目中存在requests_toolbelt依赖项是问题所在:它以某种方式强制requests库使用urllib3,而urllib3需要存在URLFetch,否则会引发AppEnginePlatformError。正如App Engine文档中建议的,通过对Requests进行monkey-patching,使用requests_toolbelt会强制前者使用URLFetch,但在Python 3运行时中,这已经不再受支持

> 您可以通过从requirements.txt文件中删除requests_toolbelt来解决此问题。

您还可以查看这个stackoverflow线程

英文:

As mentioned in this docThe Python 3 runtime doesn't need an intermediary service to handle outbound requests. If you want to migrate away from using URL Fetch APIs but still need similar functionality, you should migrate those requests to use a standard Python library such as the requests library.

As discussed in this thread seems you are also facing the similar issue

> The presence of requests_toolbelt dependency in the project was the
> problem: it somehow forced the requests library to use urllib3, which
> requires URLFetch to be present, otherwise it raises an
> AppEnginePlatformError. As suggested in the app engine docs
> monkey-patching Requests with requests_toolbelt forces the former to
> use URLFetch, which is no longer supported by GAE in a Python 3
> runtime.
>
>
> You may resolve this by removing requests_toolbelt from
> requirements.txt file

You can also have a look at this stackoverflow thread

huangapple
  • 本文由 发表于 2023年1月9日 18:46:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056150.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定