Unable to run Django project with python manage.py runserver - python

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

Related

FastAPI python app error on Azure App Service

I have a python web application that is using FastAPI. It works locally, but when I deploy it to a free linux Azure App Service (using GitHub Actions) and try to load the site it says "Internal Server Error". When I pull up the application logs I see the following error message
2023-02-06T23:44:30.765055894Z [2023-02-06 23:44:30 +0000] [90] [ERROR] Error handling request /
2023-02-06T23:44:30.765101490Z Traceback (most recent call last):
2023-02-06T23:44:30.765109589Z File "/opt/python/3.10.9/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 136, in handle
2023-02-06T23:44:30.765116389Z self.handle_request(listener, req, client, addr)
2023-02-06T23:44:30.765122088Z File "/opt/python/3.10.9/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
2023-02-06T23:44:30.765128688Z respiter = self.wsgi(environ, resp.start_response)
2023-02-06T23:44:30.765134688Z TypeError: FastAPI.__call__() missing 1 required positional argument: 'send'
Any suggestions on how to fix this issue?
I was able to resolve this issue by adding the following custom startup command in the Azure App Service Configuration General Settings
python -m uvicorn app:app --host 0.0.0.0
As h4z3 pointed out, gunicorn is wsgi and fastapi is asgi so I had to change the startup command to use uvicorn. Additional details can be found in the Azure docs here: https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#example-startup-commands

So I am trying to launch Selenium with my default browser, and it opens my default browser but when it reaches the get request I get an error [duplicate]

I am trying to run a selenium test with python script, but I am receiving the following error when executing the test:
Traceback (most recent call last):
File "/var/www/html/selenium-scripts/example.py", line 13, in <module>
driver = webdriver.Chrome()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__self.service.start()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 88, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
Please advice how to resolve this
After googling for a while, and trying various solutions. I found the one that worked for me at here:
https://github.com/SeleniumHQ/selenium/issues/2903#issuecomment-272112510
As mentioned in that comment, try to add 127.0.0.1 localhost to /etc/hosts
For MAC System:
Change the host file to default as below:
1. Command+Shift+G go to /private/etc/hosts
2.Open in Text File
3. File > Save as and uncheck the box for “If no extension is provided use txt” and rename hosts
4.Go Terminal execute command cat /etc/hosts
Check if it shows
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
For windows C:\Windows\System32\drivers\etc\hosts
Open as Administrator a Notepad then open the file hosts and do all the changes you need, in my particular case was:
0.0.0.0 localhost
to:
127.0.0.1 localhost
that fixed my problem with Selenium.

Heroku still accessing old jobs in the queue and not using the updated code

I'm trying to build a python app on Heroku. I want to upload an excel file to via botocore to a bucket hosted on AWS, but I get the following error:
2020-11-19T20:21:20.616363+00:00 app[web.1]: botocore.exceptions.NoCredentialsError: Unable to locate credentials
I modified the code to include the credentials, cleared the cache, restarted the dynos and then started the app again. Now, I get the following error (along with the credentials error described above):
2020-11-19T20:21:20.616193+00:00 app[web.1]: Started at: 2020-11-10 15:35:54.303420
2020-11-19T20:21:20.616295+00:00 app[web.1]: Ended at: 2020-11-10 15:35:57.484733
2020-11-19T20:21:20.616331+00:00 app[web.1]: Exception status: Traceback (most recent call last):
I had 2 questions here:
Why is heroku not using the updated code?
Why is it still accessing an old job even when I've cleared the cache, restarted the dynos, etc.?
Any help would be much appreciated -Thanks!
So, the way around this problem was to remove the redistogo addon and re-add it using the following commands:
heroku addons:remove redistogo --confirm <app-name>
heroku addons:add redistogo
Heroku was now reading the correct code. I had to do this every time there was an error in my code. Once, all the errors in the code were sorted out, there was no need to do this.

cherrypy https script not working with linux startup

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!!!

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