I'm working on a Django app with gunicorn right now. Everything has been working for the past couple months but today, when I tried to deploy my latest changes to my dev server, I got this error when I tried to access it:
Traceback (most recent call last):
File "/Users/ctaylor/.virtualenvs/seniordating/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
self.handle_request(listener, req, client, addr)
File "/Users/ctaylor/.virtualenvs/seniordating/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 174, in handle_request
resp.write_file(respiter)
File "/Users/ctaylor/.virtualenvs/seniordating/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 396, in write_file
if not self.sendfile(respiter):
File "/Users/ctaylor/.virtualenvs/seniordating/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 360, in sendfile
offset = os.lseek(fileno, 0, os.SEEK_CUR)
NameError: global name 'fileno' is not defined
Gunicorn command:
gunicorn --bind 0.0.0.0:8000 --pythonpath server base.wsgi_django:application
I have been unable to find anything about this online and have absolutely no idea what I did to cause this error. If anyone has any ideas, please let me know!
UPDATE
When running my server in debug mode, I get this error instead, and it shows up many more times:
Traceback (most recent call last):
File "/Users/ctaylor/.virtualenvs/seniordating/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/ctaylor/.virtualenvs/seniordating/lib/python2.7/site-packages/django/views/static.py", line 54, in serve
fullpath = os.path.join(document_root, newpath)
File "/Users/ctaylor/.virtualenvs/seniordating/lib/python2.7/posixpath.py", line 77, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
I'm having the exact same issue with a Flask app. Turns out it is a bug in Gunicorn 19.4.4. Downgrading to 19.4.3 solves the problem for me.
Reporting it upstream.
Related
I'm a beginner in web development. I'm using pycharm and django 2.1 framework
I installed django using ('py -m pip install django==2.1') and it is done.
I started myweb project using ('py -m django-admin startproject myweb .') and it also done
but when I try ('manage.py runserver') command, this is the result:
(venv) C:\Users\مرحبا\PycharmProjects\Myweb>manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 27, 2020 - 20:08:58
Django version 3.0.4, using settings 'myweb.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread <bound method Thread.name of <Thread(django-main-thread,
started
daemon 5152)>>:
Traceback (most recent call last):
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 917, in
_bootstrap_inner
self.run()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\management\commands\runserver.py", line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 206, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 67, in __init__
super().__init__(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socketserver.py", line 449, in
__init__
self.server_bind()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\wsgiref\simple_server.py", line
50,
in server_bind
HTTPServer.server_bind(self)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\http\server.py", line 139, in
server_bind
self.server_name = socket.getfqdn(host)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socket.py", line 680, in getfqdn
aliases.insert(0, hostname)
AttributeError: 'str' object has no attribute 'insert'
Could you help me please?
In the last line of the error it says
aliases.insert(0, hostname) AttributeError: 'str' object has no attribute 'insert'
Your Aliases variables is a string, not a list, so you can't .insert() to it, as that functionality doesn't exist.
You need to make sure Aliases is a list in your code.
This question already has answers here:
Unicodedecodeerror with runserver
(3 answers)
Closed 2 years ago.
I have started learning django this was my first tutorial.
First i ran django-admin startproject
This command works according to tutorial but when I run this command
python manage.py runserver
Following Error Occurs but not in tutorial video
*Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
September 27, 2019 - 18:01:04
Django version 2.2.5, using settings 'first.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last): File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\threading.py",
line 917, in _bootstrap_inner self.run() File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\threading.py",
line 865, in run
self._target(*self._args, **self._kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py",
line 54, in wrapper
fn(*args, **kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py",
line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls) File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py",
line 203, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6) File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py",
line 67, in init
super().init(*args, **kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\socketserver.py",
line 449, in init
self.server_bind() File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\wsgiref\simple_server.py",
line 50, in server_bind
HTTPServer.server_bind(self) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\http\server.py",
line 139, in server_bind
self.server_name = socket.getfqdn(host) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\socket.py",
line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position
6: invalid start byte *
You need to change hostname in Windows to remove any not UTF-8 characters.
first of all, I assume you are using the windows command-line tool as your shell.
If so, then run the command-line tool as administrator and
cd into your project directory, switch into your working(virtual environment),
then run the python manage.py runserver command again.
With these few steps you can startup your development server.
thanks
I'm sure this is my fault, but my system has been working for months and now does not work. I've looked in Django docs and here on stackoverflow, and I understand the issue that 'connection refused' means nobody is listening on the socket; but I don't understand why, and don't know how to go forward.
I use Vagrant + VirtualBox on a MacPro, and for six months I have been able to create virtual machines and run my app with no problems. I have some VM's where everything works as expected.
On my newly-created Vagrant VM's, I install and configure my django apps and run them using 'python manage.py runserver --settings=mumble.settings.py 0.0.0.0:8000'. Note that this is Django 1.8.3, but again,it works fine on some VM's.
For mysterious reasons, when I create a new vagrant VM and install my django payload (using deploy scripts that haven't changed), and connect to the django server, I get Errno 111 Connection refused:
+ python ./manage.py runserver --settings=mydjango.settings 0.0.0.0:8000
.....
_d^^^^^^^^^b_
.d'' ``b.
.p' `q.
.d' `b.
.d' `b. * Mezzanine 4.0.1
:: :: * Django 1.8.3
:: M E Z Z A N I N E :: * Python 2.7.12
:: :: * MySQL 5.7.18
`p. .q' * Linux 4.4.0-75-generic
`p. .q'
`b. .d'
`q.. ..p'
^q........p^
''''
Performing system checks...
System check identified no issues (0 silenced).
May 31, 2017 - 09:50:50
Django version 1.8.3, using settings 'mydjango.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response
'request': request
File "/usr/lib/python2.7/logging/__init__.py", line 1185, in error
Log 'msg % args' with severity 'ERROR'.
File "/usr/lib/python2.7/logging/__init__.py", line 1193, in error
self._log(ERROR, msg, args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1286, in _log
self.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1296, in handle
self.callHandlers(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
hdlr.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 759, in handle
self.emit(record)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 129, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 132, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 98, in mail_admins
mail.send(fail_silently=fail_silently)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
error: [Errno 111] Connection refused
[31/May/2017 09:50:55]"GET /donate/ HTTP/1.1" 500 59
Things I know:
'python ./manage.py' with no arguments will run fine, and shows the help message.
All forms of addressing the web server will fail:
curl http://localhost:8000
curl http://127.0.0.1:8000
curl http://192.168.33.10:8000
from a browser: http://192.168.33.10:8000
nginx is serving on port 80, no problem
my database is a copy of the production database, and it looks fine through 'mysql'
And here is a weird thing: I brought down the Django tutorial, used the 'runserver' command, and it worked!
[vagrant][~/tmp/django_tutorial/mysite]
$ python manage.py runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
May 30, 2017 - 20:36:44
Django version 1.8.3, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[30/May/2017 20:37:05]"GET / HTTP/1.1" 200 1767
Any suggestions on how to debug this?
The answer has nothing to do with my environment. My co-worker added a name to settings.ADMINS, which had been an empty list before that. When ADMINS is a non-empty list, any error triggers an attempt to send email to all of the email addresses in ADMINS, and my VM was not configured to send email. This is documented but not emphasized. The problem did not happen to my coworker, because that associated changes did not trigger a server error.
I want my logic server(Python3+Django+uwsgi+nginx) autorun when Ubuntu-server startup or reboot. So, I write a execute script (uwsgi --ini=/data/xxx.ini), and add it to /etc/rc.local .
Then, I restart server, logic-server running, But when program print log to file , python3 throw exception:
Traceback (most recent call last):
File "/usr/lib/python3.4/logging/handlers.py", line 73, in emit
logging.FileHandler.emit(self, record)
File "/usr/lib/python3.4/logging/__init__.py", line 1041, in emit
StreamHandler.emit(self, record)
File "/usr/lib/python3.4/logging/__init__.py", line 984, in emit
self.handleError(record)
File "/usr/lib/python3.4/logging/__init__.py", line 915, in handleError
traceback.print_stack(frame, file=sys.stderr)
File "/usr/lib/python3.4/traceback.py", line 286, in print_stack
print_list(extract_stack(_get_stack(f), limit=limit), file=file)
File "/usr/lib/python3.4/traceback.py", line 30, in print_list
print(item, file=file, end="")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 95-100: ordinal not in range(128)
Call stack:
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/wsgi.py", line 177, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "./carwashing/views/decorators.py", line 65, in _require_login_release
json_resp = views(request, user=token_cache.employee, *args, **kwargs)
When I direct start uwsgi in manual, it works well.
You have to write a .sh file with virtual activate code
#!/bin/bash
clear
cd /path/to your/virtual environment #path to your virtual environment
. bin/activate #Activate your virtual environment
cd /path/to your/project directory
python manage.py runserver #run django server
then write a reboot cron job for this .sh file, it will work for you.
Check this link for more details..
Out of the blue today I started having this problem.. in trying to run the Python Shell from my .py file. The shell window opens with a blinking cursor. If i type anything and hit enter the following error hits. Python IDLE doesn't work at all and I only get this error.
IDLE internal error in runcode()
Traceback (most recent call last):
File "C:\Python27\lib\idlelib\rpc.py", line 235, in asyncqueue
self.putmessage((seq, request))
File "C:\Python27\lib\idlelib\rpc.py", line 332, in putmessage
n = self.sock.send(s[:BUFSIZE])
error: [Errno 10053] An established connection was aborted by the software in your host machine
Python (command line) works fine, but the IDLE does not. I've tried rebooting windows and system restore with no luck. I've been googling for answers with little success. My firewall has always been disabled. Trying to start IDLE from command line returns the following error.
C:\Python27>python.exe -m idlelib.idle
Failed to load extension 'CallTips'
Traceback (most recent call last):
File "C:\Python27\lib\idlelib\EditorWindow.py", line 1061, in load_standard_ex
tensions
self.load_extension(name)
File "C:\Python27\lib\idlelib\EditorWindow.py", line 1076, in load_extension
cls = getattr(mod, name)
AttributeError: 'module' object has no attribute 'CallTips'
----------------------------------------
Unhandled server exception!
Thread: SockThread
Client Address: ('127.0.0.1', 49552)
Request: <socket._socketobject object at 0x0176BCA8>
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\idlelib\rpc.py", line 503, in __init__
SocketServer.BaseRequestHandler.__init__(self, sock, addr, svr)
File "C:\Python27\lib\SocketServer.py", line 649, in __init__
self.handle()
File "C:\Python27\lib\idlelib\run.py", line 276, in handle
executive = Executive(self)
File "C:\Python27\lib\idlelib\run.py", line 315, in __init__
self.calltip = CallTips.CallTips()
AttributeError: 'module' object has no attribute 'CallTips'
Windows -32bit OS. thanks in advance for your help.
This is really weird. But a great question you posted! Nice to read.
Here could be a solution: https://stackoverflow.com/a/3277996/1320237
Why would it be impossible to import the Calltips module from the standart library? Maybe you have a Python 3 idle open? Then they interfere?
Well my impatience got the best of me. I copied my site-packages file to the desktop and uninstalled/reinstalled Python. Pasted the site-packages back into my Python directory and all is right with the world again.