[英]Cannot connect to fast api server at localhost:8000 from my application which is running under a docker container
I a newbie to working with fastapi.我是使用 fastapi 的新手。 I have a main.py inside docker container.When I connect to fastapi using
我在 docker 容器中有一个 main.py。当我使用连接到 fastapi 时
uvicorn main:app —-reload
from my container.I am prompted to connect to http://127.0.0.1:8000 .从我的容器中。系统提示我连接到http://127.0.0.1:8000 。 On copying the address to Firefox I am getting the error:
将地址复制到 Firefox 时出现错误:
unable to connect.
How can I connect to fastapi server ?如何连接到 fastapi 服务器?
PS The git branch I am working from was developed by another colleague so I have little to no idea how was fastapi was set up inside the docker PS 我正在使用的 git 分支是由另一位同事开发的,所以我几乎不知道 fastapi 是如何在 docker 中设置的
You need to use the command你需要使用命令
uvicorn main:app --reload --host 0.0.0.0
A workaround solution.一种解决方法。 Through on deploy app will have public address and webdriver.Remote can take it, in dev it is ok to run selenium locally.
通过部署应用程序将具有公共地址和 webdriver.Remote 可以使用它,在 dev 中可以在本地运行 selenium。
import unittest
from selenium import webdriver
import os
from dotenv import find_dotenv, load_dotenv
from webdriver_manager.chrome import ChromeDriverManager
load_dotenv(find_dotenv())
class TestWebListAll(unittest.TestCase):
def setUp(self) -> None:
chrome_options = webdriver.ChromeOptions()
if os.environ.get("LOCAL_DEV"): # == 'True'
self.url = 'http://127.0.0.1:8000/'
self.driver = webdriver.Chrome(ChromeDriverManager().install())
else:
self.driver = webdriver.Remote(
command_executor='http://localhost:4444',
options=chrome_options
)
self.url = 'insert public addres' #
def tearDown(self) -> None:
self.driver.quit()
def test_(self):
self.driver.get(self.url)
print(self.driver.title)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.