I use python3 -m http.server --bind localhost to quickly host local versions of web content for testing.
I was using this to host a web version of a game I was working on and ran into this error:
Uncaught ReferenceError: SharedArrayBuffer is not defined
The engine I'm using has advice for this error:
Enable the following HTML response headers on the website you're hosting your project on:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
But I don't understand how to set these headers. Do I need to implement my own subclass of BaseHTTPRequestHandler (and how)? Or do I call send_header on... something?
Related
I am working on an oauth project that requires me to have a callback url that can be loaded upon successful authorization in order to request access tokens, but I'm not sure how I can run that server in the proper manner. I am familiar with the useful one-line python server setup python -m http.server, but this will just load the directory in which I started the server and act as a server for navigating the files within that directory.
Is there a preferred way to set up a simple server that can be used for this redirect process and make the additional server call I need? Would I need to use a web framework like Django?
Using python -m http.server you can serve only static files but you need to run some code which gets argument(s) and uses it.
You could use option --cgi in python -m http.server --cgi and then you could put script (in any language) in folder cgi-bin and run it http://localhost/cgi-bin/script.py.
But method with CGI is very old and it can be much easier to use some of web microframework like Flask or bottle
script.py
from flask import Flask, request
app = Flask(__name__)
#app.route('/')
def index():
print('args:', request.args) # display text in console
#print('form:', request.form)
#print('data:', request.data)
#print('json:', request.json)
#print('files:', request.files)
return request.args.get('data', 'none') # send text to web browser
if __name__ == '__main__':
app.run(port=80, debug=True)
And run it as python script.py and test in web browser
http://127.0.0.1/?data=qwerty
And request.args.get("data") should gives you qwerty which you can use in Python code.
I want to deploy my flask-restx application on a shared hosting. Since I am beginner in deployment, I followed a video tutorial from youtube.
I did step by step by following this tutorial.
For those who do not want to go through the tutorial, I am writing the steps:
I created an application from the Python cPanel
Initial set up in Cpanel
Then I opened terminal and changed my venv and installed flask by "pip install flask"
Project Structure
filas_folder/
├──public
├──tmp
│ └──restart.txt
├──app.py
└──passenger_wsgi.py
app.py looks like
from flask import Flask
app = Flask(__name__)
#app.route("/")
def main_():
return "flask is running"
#app.route("/user")
def main_2():
return "user is running"
if __name__ == "__main__": app.run()
Restart app from cpanel
passenger.py looks like
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'app.py')
application = wsgi.app
when I open www.example.com
flask is running
But when I open www.example.com/user
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#example.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
My system has cloudlinux and uses apache server. This is not the first deployment. Many wordpress and static websites are running on the server.
I opened apache logs at /usr/local/apache/logs/error_log
I get the error "Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer" http://example.com/user"
Add the following to the top of your .htaccess file:
RewriteEngine on
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]
Got this info from: https://stackoverflow.com/a/63971427/10122266
I need solution to the 403 error I'm getting after successfully deploying flask app on AWS elasticbeanstalk. After deploying a flask application developed in visual studio it gives 403 forbidden error. I've tried different searches to solve the problem but they haven't resolved it.
For example, it was suggested somewhere the start-off python file should be named - application.py, which I did and redeployed but it still didn't work. It was also mentioned in another example that the deployed solution was pointing to a folder instead of the start-off file, which is not the case in my situation.
Possible problems pointed at include the inability of subdomains to work with flask host or the need to make adjustment to the code below in my runserver.py for production environment of AWS.
if __name__ == '__main__':
HOST = environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
app.run(HOST, PORT)
I have a django application inside /home//my_app that I am trying to deploy using gunicorn:
sudo gunicorn --workers=2 -b :8081 tutorial.wsgi:application
After deploying the application with the command above, I log into another ssh instance (on the same server) and run the following command:
wget 127.0.0.1:8081
This returns a 403 FORBIDDEN.
Things I have tried:
1. Tried to chmod 755, and even 777, in app directory (Did not work)
2. Tried to move app directory to /etc/www/myapp (Did not work)
3. Tried to run all commands using root access (Did not work)
It is worth noting that I am not that familiar with linux and that this error is literally driving me crazy.
SOLVED IT:
after downloading cURL, in order to see the http header, it turned out that the service worked, but returned a 403 because a missing token authorization. Oops.
Please make sure you have coded views.py and urls.py to server GET requeat at /.
I got a simple test to work when deployed, but I get the following error from the development server:
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 301, in MakeSyncCall
assert stub, 'No api proxy found for service "%s"' % service
AssertionError: No api proxy found for service "rdbms"
Tried sample app given at https://code.google.com/apis/sql/docs/developers_guide_python.html
I tried to replicate this, and got the following warning when starting the SDK dev server:
WARNING 2011-12-27 03:50:59,069 rdbms_mysqldb.py:90] The rdbms API is
not available because the MySQLdb library could not be loaded.
What this means is that the Python-MySQL connector library is not installed on my computer.
Here's a write up on stackoverflow for how to install it: No module named MySQLdb