2

so I wrote a backend for my website with Python and FastAPI and now want to run it on my computer or phone. To run the python server I decided to use daphne, to make it reachable from a domain name, I've decided to use pagekite.

However, when I go to 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 I get an actual json response I expect. Here are the commands I used to run main.py as the backend.

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)}

Here is the whole pagekite log:

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.  

             


    

I use Linux Mint. Thanks for your help!

Petr L.
  • 414
  • 5
  • 13
  • One URL has port 8000, one URL has port 8080. – Tim Roberts Aug 24 '21 at 20:28
  • I see, but that is because of the automatic config of pagekite – Petr L. Aug 24 '21 at 20:29
  • If I change the port from 8080 to 8000 I get Temporarily Unavailable – Petr L. Aug 24 '21 at 20:30
  • If I understand the pagekite docs, you need `https://something.pagekite.me/...` without a port. It forwards port 80 or 443 to whatever local port you declared. – Tim Roberts Aug 24 '21 at 21:07
  • @TimRoberts That produces the same result, Temporarily Unavailable when I go to it in Firefox – Petr L. Aug 24 '21 at 21:26
  • `-b 0.0.0.0` means "bind to all IPv4 addresses. You shouldn’t go to `0.0.0.0` in your browser or use it in the pagekite command. Use the actual IP instead, e.g. `127.0.0.1` or `192.168.100.3`. If you are running FastAPI in Docker, then you should include that info in your question. – Alasdair Aug 25 '21 at 06:59
  • @Alasdair No, I don't use Docker. The 0.0.0.0 IP actually works but I will try your tip. – Petr L. Aug 25 '21 at 08:43
  • Cool, you mentioned Docker in one of your other questions, so I wanted to double check that you weren’t running FastAPI in Docker. – Alasdair Aug 25 '21 at 09:41
  • @Alasdair 127.0.0.1 says unable to connect while 192.168.100.3 times out. – Petr L. Aug 25 '21 at 10:14
  • When I run hostname -I I get 10.0.0.19 172.20.240.0 172.17.0.1 2001:1ae9:1a:8500:7cb7:890:3ff1:f23e 2001:1ae9:1a:8500:439:17eb:ddf9:7cb5 – Petr L. Aug 25 '21 at 10:25
  • Neither of these IPs works. Only 0.0.0.0 works – Petr L. Aug 25 '21 at 10:25
  • When I do daphne -b 172.20.240.0 -p 8000 main:app and visit that IP it works. When I do python3 pagekite.py --frontend=something.pagekite.me --service_on=http://172.20.240.0:8000 and visit the address in the browser, I get Directory listings disabled and index.html not found when I expected {"message":"Hello World"} – Petr L. Aug 25 '21 at 10:29
  • I haven't used page kite before so don't have any other suggestions. Hope you manage to get it working. – Alasdair Aug 26 '21 at 10:24
  • @PetrL. try adding http in your command `python3 pagekite.py --frontend=something.pagekite.me --service_on=http://172.20.240.0:8000` – Chandan Aug 27 '21 at 09:00
  • @Chandan That is the same adress. Will try, but if it is reachable from the browser, I don't know how adding http will help. – Petr L. Aug 27 '21 at 09:06
  • From your symptoms, it seems something related to a kite: A kite connects one or more services on your computer to a publicly visible DNS name or URL. – TASC Solutions Aug 31 '21 at 23:46
  • @PetrL. have you tried this way `pagekite.py 8000 http:something.pagekite.me`. – Chandan Sep 01 '21 at 02:20
  • @Chandan You missed two slashes between http and something. – Petr L. Sep 01 '21 at 04:47
  • @PetrL. that the syntax given in pagekite doc – Chandan Sep 01 '21 at 04:48
  • @Chandan Can you give me the link? – Petr L. Sep 01 '21 at 04:59
  • @PetrL. [pagekite](https://pagekite.net/support/quickstart/) under `Kite management` section. – Chandan Sep 01 '21 at 05:11
  • @Chandan Thanks it works! Write the answer so I can give the bounty to you. – Petr L. Sep 01 '21 at 11:19

2 Answers2

1

Info can be found in pagekite doc under Kite Management Section

pagekite.py 8000 http:something.pagekite.me
Chandan
  • 11,465
  • 1
  • 6
  • 25
-1

you are using the wrong port for the link. instead of 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