Google app engine endpoints api not working in localhost - python

I am trying to start a python app-engine project on localhost. I am in a Windows 8.1 machine (Python version 2.7). The project code is copied from here link. The server seems to start but the page wouldn't properly load due to some problem. Probably it can't reach the api server.
Here is a shot from firebug showing the failed request
What seems off to me is that in command prompt (I started the dev server from there) the API server is started at some random port other than the module port. But the webpage is trying to access the http://127.0.0.1:8000/_ah/api/static/proxy.html... page at the module port. I tried accessing it at the API server port it does open some page there. (I mean I tried opening http://127.0.0.1:1532/_ah/api/static/proxy.html... seperately) It returns some json I don't understand...
{app_id: dev~udatut-bs, rtok: '0'}
Command prompt log:
Here's the difference between the outputs in localhost and *.appspot.com
Should get this:
But stuck here:(check buttons are not loaded)

I finally found a solution here.
Steps for windows:
Goto your google appengine installation folder and then ./google/appengine/toots. (C:\Program Files (x86)\Google\google_appengine\google\appengine\tools) if you followed default installation instructions.
Open the file appengine_rpc.py and look for the line (towards the end of the file)
opener.add_handler(fancy_urllib.FancyProxyHandler())
and comment it out like
# opener.add_handler(fancy_urllib.FancyProxyHandler())
Close the app and restart it again.

Related

I've created a simple .onion site, but instead of the Tor browser displaying my index.html file, it displays my folders

This is my first question so please bear with me. I looked for answers to my question, but found none unique to my issue.
I recently tried my hand at hosting an onion site with Python3 and the Tor browser. I created a directory called "tor_service" and placed a simple index.html file inside.
I then ran python3 -m http.server --bind 127.0.0.1 8080 in the same folder. Next, I opened another terminal session and started the Tor client. I navigated to, and appropriately modified the torrc file under the "hidden services" section, using port 8080. I opened my browser and went to localhost:8080 to verify everything was working. To my surprise, I saw the simple web page I wrote. So far, so good.
I then navigated to the Tor folder that contained the hostname to get the unique oinion address, and using cat hostname, obtained the string of characters followed by .onion.
I pasted the onion address in the Tor browser and again, I saw the simple html page I wrote.
Here's the problem: when I shut down my computer for the night, resumed the next day, and started the Python server and Tor client, instead of displaying my web page, I got a page that read "Directory of /" that displayed all of the folders on my hard drive. This is obviously a serious security issue. Not only were the folders on my hard drive on display for the web to see, they were all hyperlinks.
I don't understand what I did wrong. I didn't modify or move any files or change any settings, and I started the Python http.server and Tor client as usual.
I closed the terminal windows opened new ones, but got the same results. A third time resulted in the same outcome. I understand that using the Python "server" isn't the optimal method to host a site, but if I can't get something so simple to work, I fear I won't be able to actually write (much less diagnose problems on) a more robust server that operates using more than a single line of code.
I'm using the Linux subsystem on Windows 10 and the latest iteration of Ubuntu (20.4, I think).
Any pointers are greatly appreciated. I can craft and style a nice looking webpage, but I'd like to get proficient at the back-end side of things.
Are you sure you have navigated back to the project folder in your terminal?
If you're running the
python3 -m http.server --bind 127.0.0.1 8080
command immediately after opening the terminal, it will run in the 'default' folder rather than your project folder (you'll need to 'move' back into the project folder using cd).

Stop Python localhost server on every port

Since I tried a tutorial with Python / Django using venv etc, i'm blocked with a localhost server that shows folder of this project:
I use Visual Studio Code and I use LiveServer configured on port 0. Each time I want to start LiveServer, it renders me this page and nothing else.
Have you any idea why and how to stop it?
I modified my PATH folder to make the Python's project work. Is it the problem?
Thank you
The way to fix this is by going to VS Code >> File >> Open Folder, and the select the folder with your html file in it then you can run live server properly. However, if you want to stop live server simply closing the web browser it's running on will do.

Running a Python script that creates a webpage on a server

I have a Python script that creates a web page displaying some text at localhost port 8080. I have access to a server, and would the script to run there so that it is always running and available anywhere.
I am using the bottle, requests and json libraries.
This is the last line of code in the script that is executed to locally create a web page:
run(host='localhost', port=8080, debug=True)
How would I change this to run on a server? I also have WinSCP and PuTTy to add the script to the public_html directory of the server and I can change permissions. Sorry, I am a novice in this subject.
Thanks for any help!
That depends on the Apache httpd configuration. But, assuming most defaults were left in place and Apache httpd serves index.html, you can just create your webpage (which you tested locally on port 8080) and overwrite that file. But, this only works well if you have a static page and no logic in your Python code. If you want to combine the power of Apache httpd and Python (have the former call the latter) you'll have to use mod_wsgi.
Seeing as you're novice in this subject, I suggest starting off with a simple Apache httpd server according to their quickstart. Then, once you have a few successful requsets under your belt, add mod_wsgi.

Local Chromecast receiver not loading

I am developing a Chromecast app and currently host it locally for development purpose.
It used to work fine when I had an internal ip set as my receiver url (http://192.168.1.167:9000/receiver.html) and hosted a server on my Windows machine using
python -m http.server 9000.
Now my laptop broke and I'm working on a mac mini (also because i was going to develop an iOS sender app for my receiver anyway) so I'm trying to get the receiver hosted on the mac mini.
I'm using the same principe, internal ip of the mac-mini set as receiver url, started a server using
Python -m SimpleHTTPServer 9000.
When I try to connect to my receiver, I can't get it to load.
The Chromecast displays:
Cannot load sources (or some other english equivalent of my dutch error: 'De bronnen kunnen niet geladen worden'.)
I forwarded a port in my router to my receiver and I can reach it from outside my own network (mobile 4g), I can reach it internally, colleagues can reach it, it's just the Chromecast which somehow refuses to load the page and I can't figure out why.
The Android SDK gives me CastStatusCode.CANCELED and iOS SDK GCKErrorCodeCancelled.
I also tried to update Python to the latest version, but it didn't fix it.
The Chromecast loads other apps fine, I can ping to the Chromecast and to my devices. When the Chromecast attempts to load the app, I can briefly load the debugger but it doesn't display anything in either network or console.
I hope someone has had a similair issue or any clue on how I can get the Chromecast to connect to my server again.
Of all the things i tried the last couple of hours, I didn't think of the basic 'Have you tried rebooting it'....
Cause was firmware update...

How can I create an local webserver for my python scripts?

I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.
I've been looking, therefore, for a lightweight web server that can execute python scripts, sitting in the background on a machine, ideally as a Windows service. Security and extensibility are not high priorities as it's all running internally on a small network.
Should I run a native python webserver as a Windows service (in which case, how)? Or is it just as easy to install Apache onto the user's machine and run as CGI? Since this is all local, performance is not an issue either.
Or am I missing something obvious?
Don't waste a lot of time creating Windows service.
Don't waste a lot of time on Windows Apache.
Just make a Python service that responds to HTTP requests.
Look at https://docs.python.org/2/library/basehttpserver.html
https://docs.python.org/3/library/http.server.html for version 3
Python offers an HTTP server that you can extend with your server-side methods.
Look at http://docs.python.org/library/wsgiref.html
Python offers a WSGI reference implementation that makes your server easy and standards-compliant.
Also http://fragments.turtlemeat.com/pythonwebserver.php
"I'm trying to avoid making the user run python stuff from the command prompt."
I don't see how clicking a web page is any different from clicking desktop icons.
Starting a web server based on Python is relatively easy, once you have the web server. First, build the server. Later, you can make sure the server starts. Let's look at some ways.
Your user can't use a random browser to open your local page. They need a bookmark to launch "localhost:8000/myspecialserverinsteadofthedestop/" That bookmark can be a .BAT file that (1) runs the server, (2) runs firefox with the proper initial URL.
You can put the server in the user's start-this menu.
You can make your Python program a windows "service".
Best way is to make your own local server by using command prompt.
Make a new folder say Project
Make a new folder inside project & name it as "cgi-bin"(without quotes)
Paste your .py file inside the cgi-bin folder
Open cmd and change to the directory from which you want to run the server and type "python -m CGIHTTPServer"(without quotes)
Minimize the cmd window & open your browser and type "localhost:8000/cgi-bin/yourpythonfilename.py"(without quotes).
The wasiest step would be navigate to folder where your files are located and running http.server module
cd /yourapp
python3 -m http.server
the you should see something like this in console
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Running a native python webserver as a windows service should be a no brainer. Check out the documentation for writing windows services (win32api, ActiveState python) in python and also the documentation for subclassing BaseHttpServer and SimpleHttpServer.
BTW: I had a similar question on stackoverflow: How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?
Basically, you subclass BaseHTTPServer (you have to anyway...) and then... but just read the accepted answer - it set me on the right track!

Categories

Resources