cherrypy https script not working with linux startup - python

Trying to run a cherrypy https server on linux startup. The startup script works with cherrypy running http, but not https. Also, when running https server manually it works, so no library issues there. The summary and error is below:
https and http server are working when running it manually on linux
http is working on linux startup
https is not working on linux startup
I output the results of the https startup script to a text file, and this error is encountered:
[25/Feb/2015:13:59:03] ENGINE Bus STARTING
[25/Feb/2015:13:59:03] ENGINE Started monitor thread '_TimeoutMonitor'.
[25/Feb/2015:13:59:03] ENGINE Started monitor thread 'Autoreloader'.
[25/Feb/2015:13:59:03] ENGINE Serving on 0.0.0.0:8099
[25/Feb/2015:13:59:03] ENGINE Bus STARTED
[25/Feb/2015:13:59:03] ENGINE Error in HTTPServer.tick
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cherrypy/wsgiserver/wsgiserver2.py", line 1837, in start
self.tick()
File "/usr/local/lib/python2.7/site-packages/cherrypy/wsgiserver/wsgiserver2.py", line 1902, in tick
s, ssl_env = self.ssl_adapter.wrap(s)
File "/usr/local/lib/python2.7/site-packages/cherrypy/wsgiserver/ssl_builtin.py", line 52, in wrap
keyfile=self.private_key, ssl_version=ssl.PROTOCOL_SSLv23)
File "/usr/local/lib/python2.7/ssl.py", line 387, in wrap_socket
ciphers=ciphers)
File "/usr/local/lib/python2.7/ssl.py", line 141, in __init__
ciphers)
SSLError: [Errno 336265218] _ssl.c:351: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib
I set the permissions on the folder containing the script to "chmod 777", i.e. grant all permissions to all users/groups. No luck.

You are most likely setting a relative path to the certificate or maybe it does not have read permission.
Double check the path to the certificate. Use an absolute one and keep an eye for any required escape character. \

Fixed the solution, cyraxjoe is right. It ended up being the init.d script was running the python server file from etc/init.d/, and the private key file was using a relative path. Using the absolute path ended up solving the problem.
Thanks!!!

Related

Unable to run Django project with python manage.py runserver

I am new my first clone blog project in Django by trying:
python manage.py runserver
I see the following output:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 19, 2020 - 13:15:32
Django version 3.0.4, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
Git
GitHub
Create Repository
Initialize /home/user/Desktop/project with a Git repository
Create repository .............................etc
I can't access it in a browser via http://127.0.0.1:8000, instead it is showing the standard Firefox 'Unable to connect' error page:
The text says:
Unable to connect
Firefox can't establish a connection to the server at 127.0.0.1:8000.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
Added image after executing command said by sir:
enter image description here
this is my project : my project

git webhook fails - do you know why?

Background:
I have a bitbucket repo called DOSTUFF that includes a python script do_stuff.py. I edit it using Eclipse pydev on my local machine and push changes to bitbucket via git push origin master.
I cloned DOSTUFF to a pythonanywhere trial account without any issues.
Now, whenever I edit do_stuff.py locally and then git commit -m 'foo' & git push origin master them to bitbucket, I manually need to git pull from within pythonanywhere afterwards in order to see the edits in pythonanywhere. This is inefficient.
Objectives:
I want that my local (Eclipse) commits to bitbucket get pulled automatically to pythonanywhere once pushed from local to bitbucket. Apparently, webhooks are the way to go.
Challenges:
In order to do so, I followed this hint by specifying a webhook within bitbucket to pythonanywhere/user/me/webhook.py. Unfortunately, those instructions are minimalistic as they lack proper imports and don't elucidate as to why flask is necessary (I am not an expert).
webhook.py looks like this:
#!/usr/bin/python2.7
# -*- coding: utf-8 -*
import git
from flask import Flask, request
# Initiate flask instance
app = Flask(__name__)
#app.route('/webhook', methods=['POST'])
def webhook():
if request.method == 'POST':
repo = git.Repo('./DOSTUFF')
origin = repo.remotes.origin
repo.create_head('master',
origin.refs.master).set_tracking_branch(origin.refs.master).checkout()
origin.pull()
return '', 200
else:
return '', 400
if __name__ == '__main__':
app.run(port=5000,debug=True)
Now, when I git push from Eclipse to bitbucket, the commit(s) arrive at bitbucket but the code in pythonanywhere remains unchanged. In other words, webhook.py fails.
In contrast, when I run webhook.py from within pythonanywhere (bash console), I yield the following error:
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
Traceback (most recent call last):
File "/home/ME/webhook.py", line 21, in <module>
app.run(port=5000,debug=True)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 943, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 795, in run_simple
s.bind(get_sockaddr(hostname, port, address_family))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use
Questions:
What's the root cause for this to fail?
How to properly configure a webhook that is necessary and sufficient to auto-git pull changes to pythonanywhere once pushed from local to bitbucket?
You're trying to start a server in a PythonAnywhere console, which will not work since traffic is not routed to console servers. Use a web app to create the server to listen for the web hooks.

Flask Google Cloud App Engine: OSError: [Errno 98] Address already in use

I am trying to deploy a flask app on google cloud app engine. It runs smooth in my virtual environment locally but I get an 502 error running it in the cloud.
Now I am trying to debug my code on the cloud server, using debug mode and SSH into my instance. Using docker exec -it [ID] /bin/bash I am able to to access the root of my application. Now I upon running python app.py I get the following error:
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "app.py", line 479, in <module>
app.run(port=8080)
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 941, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple
inner()
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner
fd=fd)
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 660, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__
self.address_family), handler)
File "/usr/local/lib/python3.6/socketserver.py", line 453, in __init__
self.server_bind()
File "/usr/local/lib/python3.6/http/server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/local/lib/python3.6/socketserver.py", line 467, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use
I've been trying to kill those processes listed when I run:
ps -fA | grep python
However, this does not solve the problem of the address being in use. Also changing the port in the app.run() does not solve the issue for me.
I had a similar problem, it was caused by the Flask app also being run when the module was loaded, because I had
if __name__ == "__main__":
app.run()
at the bottom. Note that the recent requirement to name your sever file "main.py" could cause this bug to emerge.
I think the problem is that you don't need to specialize the port for cloud. Google Cloud finds the port to run your app on its own. So instead of app.run(port=8080) just write app.run()
While I was not able to figure out how to "free" the running address, I solved the problem by starting another flask process by running it on a different port like so:
flask run --port=80

Flask basic app using OpenShift's own suggested approach: permission denied for git push

I'm building a small Flask app that will have user login, and a few other pages that will allow the user to run queries against a database.
Using the Flask User basic app as an example, I put togther a skeleton of the app, and it is working fine locally. Then in an attempt to deploy at as my first Flask app on OpenShift, I follow the guide here (changing flaskapp.py to basic_app.py). For requirements.txt, I add in all the libraries that were required by Flask, Flask User, Flask Login, and some other libraries I will need such as lxml.
When I attempt git push, I get:
remote: Traceback (most recent call last):
remote: File "/var/lib/openshift/56c60ef92d5271a900000016/python/virtenv/bin/pip", line 12, in <module>
remote: load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
remote: File "/var/lib/openshift/56c60ef92d5271a900000016/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/__init__.py", line 148, in main
remote: return command.main(args[1:], options)
remote: File "/var/lib/openshift/56c60ef92d5271a900000016/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/basecommand.py", line 171, in main
remote: log_fp = open_logfile(log_fn, 'w')
remote: File "/var/lib/openshift/56c60ef92d5271a900000016/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/basecommand.py", line 200, in open_logfile
remote: os.makedirs(dirname)
remote: File "/var/lib/openshift/56c60ef92d5271a900000016/python/virtenv/lib64/python2.7/os.py", line 157, in makedirs
remote: mkdir(name, mode)
remote: OSError: [Errno 13] Permission denied: '/var/lib/openshift/56c60ef92d5271a900000016/.pip'
When running rhc app create prior to this, I did see the following:
Cloning into 'myflaskapp2'...
The authenticity of host 'myflaskapp2-pyderman.rhcloud.com ' can't be established.
RSA key fingerprint is ......
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'myflaskapp2-pyderman.rhcloud.com' (RSA) to the list of known hosts.
Your application 'myflaskapp2' is now available.
The fact that it finished with 'your application is now available' though would suggest that things are OK with with the SSH key.
I've taken a look at this post, but it doesn't shed any light, as I don't think I am running a "DIY" application (whatever that is).
Any help much appreciated.
I know is late but I faced the same problem yesterday and I was able to solve it.
This happens when there's already a socket in the port your app is using. What to do? SSH into you server, kill your app process and push again.
Another option is that you're using the wrong port. You should use the port and IP from the environment variables (if you are using Python: OPENSHIFT_PYTHON_IP and OPENSHIFT_PYTHON_PORT)
About your second question: If you used a custom cartridge or use diy-0.1 cartridge then your app is running over diy. If you used python-2.6, 2.7 or 3.3 then is not.

PyCharm remote debugging

I have remote Ubuntu server, and I'm trying set up remote debugging.
Configured as shown here.
import sys
import pydevd
sys.path.append('/root/home/scripts/pycharm-debug.egg')
pydevd.settrace('my_remote_server_IP', port=51234,
stdoutToServer=True, stderrToServer=True)
I also connect remote host for synchronizing and uploading my python scripts to remote server. (Tools -> Deployment -> ...)
When I start debugging:
C:\Python27\python.exe C:/Projects/python/demo.py
Could not connect to xx.xx.xx.166: 51234
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.1\helpers\pydev\pydevd_comm.py", line 428, in StartClient
s.connect((host, port))
File "C:\Python27\Lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10061] ����������� �� �����������,
Process finished with exit code 1
How to solve this problem?
The first argument of pydevd.settrace function should be the host, where PyCharm is installed. Not remote server.
Also in most cases if you want to run and debug your code remotely it is more convenient to use remote interpreter feature.
I resolved this problem by changing the port.

Categories