尝试使用 daphne 服务器和 pagekite 时出现错误 404 而不是 json

Getting Error 404 instead of json when trying to use daphne server and pagekite

所以我用 Python 和 FastAPI 为我的网站编写了一个后端,现在想 运行 它在我的计算机上或 phone。对于 运行 python 服务器,我决定使用 daphne,以便可以通过域名访问它,我决定使用 pagekite。

但是,当我转到 https://something.pagekite.me:8080/coordinates/?direction_x=1&direction_y=2&gas=2 (not the actual domain name), I get 404 Not found File or directory not found. Sorry! When I go to http://0.0.0.0:8000/coordinates/?direction_x=1&direction_y=2&gas=2 时,我得到了我期望的实际 json 响应。 这是我用来 运行 main.py 作为后端的命令。

daphne -b 0.0.0.0 -p 8000 main:app

python3 pagekite.py --frontend=something.pagekite.me --service_on=http://0.0.0.0:8000

main.py:

from fastapi import FastAPI
from datetime import datetime
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()


origins = ["*"]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.get("/")
def root():
    return {"message": "Hello World"}

directionX = 0
directionY = 0
Gas = 0
@app.get("/coordinates/") #post is used to get data, but I can send it using get and query parameters response_model=Item)
def getcoordinates(direction_x,direction_y,gas): #http://127.0.0.1:8000/coordinates/?direction_x=0&direction_y=10&gas=50
    global directionX,directionY, Gas #changed async def to def 
    directionX = direction_x
    directionY = direction_y
    Gas = gas
    return {"data":(direction_x,direction_y,gas)}

这是整个 pagekite 日志:

python3 pagekite.py --frontend=something.pagekite.me --service_on=http://172.20.240.0:8000
>>> Hello! This is pagekite.py v1.5.2.201011.                   [CTRL+C = Stop]
    Built-in HTTPD is on localhost:43503, secret=CCV0mPEbKJ+ZGhi_7SQT+MYr      
Exception in thread Thread-7:arting up...                                      
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "<string>", line 3452, in sping
ValueError: not enough values to unpack (expected 2, got 1)
    Connecting to front-end relay 159.69.241.220:443 ...                       
     - Relay supports 10 protocols on 19 public ports.                         
     - Raw TCP/IP (HTTP proxied) kites are available.                          
     - To enable more logging, add option: --logfile=/path/to/logfile          
    Abuse/DDOS protection: Relaying traffic for up to 5 clients per 10800s.    
    Quota: You have 26 days, 5.0 tunnels left.                                 
~<> Flying builtin HTTPD as https://drooon.pagekite.me:8080/                   
     - https://something.pagekite.me:8080/                                        
    93.153.49.187 < http://something.pagekite.me:8080 (builtin)                   
 << pagekite.py [flying]   Kites are flying and all is well.  

             


    

我用 Linux Mint。 感谢您的帮助!

您为 link 使用了错误的端口。 而不是 https://something.pagekite.me:8080/coordinates/?direction_x=1&direction_y=2&gas=2 try https://something.pagekite.me:8000/coordinates/?direction_x=1&direction_y=2&gas=2

可以在 pagekite 文档 Kite Management 部分

下找到信息
pagekite.py 8000 http:something.pagekite.me