Openshift python gear wont deploy - python

I have a problem with my most recent openshift gear , i get the python error errno 13 , Permission denied. I have checked around on here and found that most people who have gotten the same issue have just forgot the if __name__ == "__main__": statement before the app.run(), but i still have the same issue. According to the log on openshift, the error seems to be rooting from the socket.py built in to python.
This is my second gear on openshift and both this and my first one is built using flask. The first one works just fine but my second one wont work ...
This is the error message I get in the python log from openshift:
* Running on http://127.0.0.1:5000/
Traceback (most recent call last):
File "app.py", line 24, in <module>
app.run()
File "/var/lib/openshift/54d242655973ca23980001d1/python/virtenv /lib/python2.7/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 617, in run_simple
inner()
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 599, in inner
passthrough_errors, ssl_context).serve_forever()
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 408, in make_server
passthrough_errors, ssl_context)
File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 334, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/opt/rh/python27/root/usr/lib64/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/opt/rh/python27/root/usr/lib64/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/opt/rh/python27/root/usr/lib64/python2.7/SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "/opt/rh/python27/root/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied
EDIT 2:
So i changed the ip to OPENSHIFT_PYTHON_IP but the errorlog looked exactly the same. This is my wsgi.py code
#!/usr/bin/python
import os
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
def run_gevent_server(app, ip, port=8080):
from gevent.pywsgi import WSGIServer
WSGIServer((ip, port), app).serve_forever()
def run_simple_httpd_server(app, ip, port=8080):
from wsgiref.simple_server import make_server
make_server(ip, port, app).serve_forever()
from server import app as application
#
# Below for testing only
#
if __name__ == '__main__':
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = 8080
zapp = impo.load_source('application', 'wsgi/application')
try:
run_gevent_server(application, ip, port)
except:
run_simple_httpd_server(zapp.application, ip, port)

What port/ip address are you using? You must bind to port 8080 of your openshift ip address, you can't bind to 127.0.0.1, it is not allowed.

Related

An attempt was made to access a socket in a way forbidden by its access permissions (Bottle) (Python)

I've written this code and then ran it via the CMD. However when I ran the code this occurred.
Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:80/
Hit Ctrl-C to quit.
Traceback (most recent call last):
File "bottle_01.py", line 7, in <module>
run(host='localhost', port = 80, debug=True)
File "C:\Users\Owner\Desktop\BottleWebApp\bottle.py", line 3137, in run
server.run(app)
File "C:\Users\Owner\Desktop\BottleWebApp\bottle.py", line 2789, in run
srv = make_server(self.host, self.port, app, server_cls, handler_cls)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\wsgiref\simple_server.py", line 154, in make_server
server = server_class((host, port), handler_class)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\socketserver.py", line 452, in __init__
self.server_bind()
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\wsgiref\simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\http\server.py", line 138, in server_bind
socketserver.TCPServer.server_bind(self)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
Now I asked my professor but he's unfamiliar with the issue himself. I searched stackoverflow and I tried to disable my firewall but that didn't seem to help. Any suggestions? Is it an administration issue perhaps? My original code is below.
from bottle import route, run, static_file
#route('/')
def index():
return static_file('webpage_01.html' , root= 'C:/Users/Owner/Desktop/BottleWebApp')
run(host='localhost', port = 80, debug=True)
Does this problem go away when you try port 8000 instead of 80?
You're trying to bind to port 80. I don't know Windows, but on Linux your code would fail because port 80 (like all ports below 1024) is privileged--only root can bind to them. That's why you'll see most tutorials and web framework defaults use a high port number, typically 8000 or 8080.
References:
https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html
https://en.wikipedia.org/wiki/Registered_port

Permission denied while starting a flask app at port 80 in AWS EC2 instance

I have developed a flask based app which is running successfully at my local machine / network.
I deployed it to an AWS EC2 instance. Started it like this:
flask run --host <private ip within AWS>
but when I tried to access an implemented API through Postman, I got following error in Postman console:
Error: connect ECONNREFUSED <IPv4 Public IP within AWS>
Noticed that it might be due to the fact that flask app typically runs on port 5000, however the EC2 has inbound rule of type http bound to port 80.
So I changed my flask code to:
if __name__ == "__main__":
app = create_app()
app.run(host='<private ip within AWS>', port=80)
And tried to run it like this in AWS ec2 instance:
python3 apiapp.py
However I got following stack trace while trying to run the app:
Traceback (most recent call last):
File "apiapp.py", line 49, in <module>
app.run(host='<private ip within AWS>', port=80)
File "/home/ec2-user/AwesomeAPIs/venv/lib64/python3.7/site-packages/flask/apiapp.py", line 990, in run
run_simple(host, port, self, **options)
File "/home/ec2-user/AwesomeAPIs/venv/lib64/python3.7/site-packages/werkzeug/serving.py", line 1052, in run_simple
inner()
File "/home/ec2-user/AwesomeAPIs/venv/lib64/python3.7/site-packages/werkzeug/serving.py", line 1005, in inner
fd=fd,
File "/home/ec2-user/AwesomeAPIs/venv/lib64/python3.7/site-packages/werkzeug/serving.py", line 848, in make_server
host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
File "/home/ec2-user/AwesomeAPIs/venv/lib64/python3.7/site-packages/werkzeug/serving.py", line 740, in __init__
HTTPServer.__init__(self, server_address, handler)
File "/usr/lib64/python3.7/socketserver.py", line 452, in __init__
self.server_bind()
File "/usr/lib64/python3.7/http/server.py", line 137, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib64/python3.7/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
PermissionError: [Errno 13] Permission denied
Am I missing anything obvious over here?

"Address already in use" Error while using LinkedIn API

I was trying to use Linkedin API to scrape information about companies but i had a socket error:
Traceback (most recent call last):
File "/Users/anhvangiang/Desktop/PY/test.py", line 10, in <module>
application = server.quick_api(key, secret)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/linkedin/server.py", line 25, in quick_api
_wait_for_user_to_enter_browser(app)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/linkedin/server.py", line 39, in _wait_for_user_to_enter_browser
httpd = BaseHTTPServer.HTTPServer(server_address, MyHandler)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 417, in __init__
self.server_bind()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 431, in server_bind
self.socket.bind(self.server_address)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 48] Address already in use
My code is:
from linkedin import server
from socket import *
sock = socket()
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
key = "key"
secret = "secret"
application = server.quick_api(key, secret)
Any suggestions how can i fix the problem ?
You could find and kill the process using the:
ps aux | grep python
Get the process id and kill using:
kill -9 PID
It will free the address.
OR you can try :
application = server.quick_api(key, secret, 5557)

GAE/Flask [Errno 13] Permission denied

As the title suggests, I am seeing this error when my flask app tries to run.
I am hosting the application locally using dev_appserver.
The error occurs when I visit the site and it tries to run the app. It appears that GAE is trying and failing to bind a socket for some reason.
I suspect that this may have something to do with OAuth2. Maybe it requires an SSL connection?
I don't even know where to begin solving this as none of the other posts about this are experiencing the same variation of the issue.
Edit: Here's a screenshot of the console confirming that the GAE server launches successfully on a different port; still doesn't resolve it
Traceback (most recent call last):
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "C:\Users\XXX\PycharmProjects\ad-assignment\main.py", line 51, in <module>
app.run()
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\flask\app.py", line 843, in run
run_simple(host, port, self, **options)
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 694, in run_simple
inner()
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 656, in inner
fd=fd)
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 550, in make_server
passthrough_errors, ssl_context, fd=fd)
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 464, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "C:\Python27\Lib\SocketServer.py", line 417, in __init__
self.server_bind()
File "C:\Python27\Lib\BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "C:\Python27\Lib\SocketServer.py", line 431, in server_bind
self.socket.bind(self.server_address)
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\dist27\socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\remote_socket\_remote_socket.py", line 676, in bind
raise _SystemExceptionFromAppError(e)
error: [Errno 13] Permission denied
INFO 2016-12-16 21:41:51,631 module.py:788] default: "GET /oauth2callback?code=x/xxxxxxxxxxxxxxxxx HTTP/1.1" 500 -
Code (as seen in Google's OAuth2 usage guide):
import flask
app = flask.Flask(__name__)
#app.route('/')
def index():
...
#app.route('/oauth2callback')
def oauth2callback():
...
if __name__ == 'main':
import uuid
app.secret_key = str(uuid.uuid4())
app.debug = False
app.run()
We have a tutorial that walks you through adding Firebase Authentication to your Python app running with Flask. Firebase Authentication is the preferred identity toolkit now. You can of course still use a pure OAuth2 flow, but Firebase Auth also provides multi-provider authentication if that's something you were considering adding to your app anyways. If you just want to dive into the sample's code its here on GitHub.
If you just want to stick with straight OAuth, you might want to look at your Flask code itself. Getting flask to run is pretty easy on App Engine. My guess is that you're calling some code that you don't need to (flask.run()) or you aren't importing your library properly (see appengine_config.py).

Flask, cannot assign requested address [duplicate]

This question already has answers here:
socket.error:[errno 99] cannot assign requested address and namespace in python
(6 answers)
Closed 8 years ago.
I'm trying to run a flask app on a remote server, so I can access it from other computers. The server has a public IP and I configured the flask to run on that IP. But when I run the script I get the following traceback
Note: I've removed the public IP from the traceback and my code.
* Running on **public ip**
Traceback (most recent call last):
File "testServer.py", line 14, in <module>
app.run(host='62.60.19.189',port=5000)
File "/usr/lib/python2.6/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 710, in run_simple
inner()
File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 692, in inner
passthrough_errors, ssl_context).serve_forever()
File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 486, in make_server
passthrough_errors, ssl_context)
File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 410, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/usr/lib64/python2.6/SocketServer.py", line 402, in __init__
self.server_bind()
File "/usr/lib64/python2.6/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/usr/lib64/python2.6/SocketServer.py", line 413, in server_bind
self.socket.bind(self.server_address)
File "<string>", line 1, in bind
socket.error: [Errno 99] Cannot assign requested address
Here is my code
import flask
app = flask.Flask("My app")
#app.route('/myroute', methods=['POST'])
def foobar():
print flask.request.form
return '<br>'.join('{0}: {1}'.format(*pair) for pair in flask.request.form.items())
if __name__ == '__main__':
app.run(host='public IP',port=5000)
You can only directly bind to an IP address that the server has been configured for; behind a router running Network Address Translation (NAT) your internal IP address will be different.
Either bind directly to that internal IP address, or use '0.0.0.0' to listen on all interfaces. You may still need to configure the router to forward a specific port to your internal server.
The IP you want to bind a socket to must be directly available on an interface of the machine. This seems not be the case here.
If you're behind a NAT: use port-forwarding
If you're using a VPN and the VPN adapter of the server is not always up, try using "0.0.0.0" as an address. Beware: It will listen on all interfaces available. Create firewall rules to block access via interfaces you don't want to listen to when using this.

Categories

Resources