Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 使用0.0.0.0 在局域网 使用会有问题 #837

Open
xieyan110 opened this issue Feb 2, 2025 · 1 comment
Open

[Bug]: 使用0.0.0.0 在局域网 使用会有问题 #837

xieyan110 opened this issue Feb 2, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@xieyan110
Copy link

Issue

使用 https://sleazyfork.org/zh-CN/scripts/374903-comicread 这个插件访问 本地服务 失败了。
不过我找到了解决办法
就是搞一个证书 openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365

main.py 文件这样改一下。

# main.py
if __name__ == '__main__':
    import uvicorn
    from args import parse_arguments

    args = parse_arguments()
    args.start_instance = True
    proc = prepare(args)
    print("Nonce: "+nonce)
    try:
        uvicorn.run(app, host=args.host, port=args.port, ssl_keyfile="key.pem", ssl_certfile="cert.pem")
    except Exception:
        if proc:
            proc.terminate()

貌似 instance.py 这里也要改一下,不然局域网请求也会出错。

# instance.py

import socket

def get_local_ip():
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 80))
        ip = s.getsockname()[0]
        s.close()
        return ip
    except Exception as e:
        print(f"Error getting local IP: {e}")
        return None


class ExecutorInstance(BaseModel):
    ip: str
    port: int
    busy: bool = False

    def free_executor(self):
        self.busy = False

    async def sent(self, image: Image, config: Config):
        self.ip = get_local_ip()
        print(f"self.ip={self.ip}")
        return await fetch_data("http://"+self.ip+":"+str(self.port)+"/simple_execute/translate", image, config)

    async def sent_stream(self, image: Image, config: Config, sender: NotifyType):
        self.ip = get_local_ip()
        print(f"self.ip={self.ip}")
        await fetch_data_stream("http://"+self.ip+":"+str(self.port)+"/execute/translate", image, config, sender)

run.bat 里面用 python -m manga_translator %* 貌似会失败

# run.bat
python main.py --verbose --use-gpu  --host 0.0.0.0 --port 5003 

Command Line Arguments

Console logs

@xieyan110 xieyan110 added the bug Something isn't working label Feb 2, 2025
@zyddnys
Copy link
Owner

zyddnys commented Feb 5, 2025

可以发个pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants