Error while Running Python manage.py runserver comman [duplicate] - django

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

Related

Failed Manage.py runserver command

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.

trying to use cookiecutter-django, getting errors and does not create anything

trying to get a Django project started using cookiecutter-django and can't seem to get it to generate anything.
using Python 3.6, Django 2.0.5, cookiecutter 1.6.0 (then created a virtualenv and entered a new, blank directory)
so I enter this command:
cookiecutter https://github.com/pydanny/cookiecutter-django
and get this error traceback:
Traceback (most recent call last):
File "c:\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Python\python36\Scripts\cookiecutter.exe\__main__.py", line 9, in
<module>
File "c:\python\python36\lib\site-packages\click\core.py", line 722, in
__call__
return self.main(*args, **kwargs)
File "c:\python\python36\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\python\python36\lib\site-packages\click\core.py", line 895, in
invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\python\python36\lib\site-packages\click\core.py", line 535, in
invoke
return callback(*args, **kwargs)
File "c:\python\python36\lib\site-packages\cookiecutter\cli.py", line 120,
in main
password=os.environ.get('COOKIECUTTER_REPO_PASSWORD')
File "c:\python\python36\lib\site-packages\cookiecutter\main.py", line 63,
in cookiecutter
password=password
File "c:\python\python36\lib\site-packages\cookiecutter\repository.py", line
103, in determine_repo_dir
no_input=no_input,
File "c:\python\python36\lib\site-packages\cookiecutter\vcs.py", line 99, in
clone
stderr=subprocess.STDOUT,
File "c:\python\python36\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "c:\python\python36\lib\subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'clone',
'https://github.com/pydanny/cookiecutter-django']' returned non-zero exit
status 128.
OK - figured out how to get this to work.
used Github desktop
from cookiecutter-django repository, right click
open it Git Shell
this opens a Powershell window.
CD to directory where project will be placed in.
cookiecutter https://github.com/pydanny/cookiecutter-django
and it works.
not sure exactly why this works when regular CMD and elevated CMD do not, but this was the only way I could get it to work.
This is a permission issue with github due to the need to setup ssh keys. By the way I'm using ubuntu 12.
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ - create a key first in your machine using the instructions in the link. Once you have your ssh key, proceed to step 2. (Step 2 is indicated in the first link as last step)
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account - add the generated ssh key to your github account.

Trying to setup a Ghost blog with Buster

I'm trying to set up a static Ghost blog with Github hosting using the Buster Static generator. I've tried various instructions including:
https://stefanscherer.github.io/setup-ghost-for-github-pages/
http://blog.sunnyg.io/2015/09/24/ghost-with-github/
But when I get to the "buster generate" command I get the following output in terminal.
It is running fine locally.
Can anyone point me in the right direction?
buster generate
--2016-03-07 23:53:11-- http://localhost:2368/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:2368... failed: Connection refused.
Connecting to localhost|127.0.0.1|:2368... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4508 (4.4K) [text/html]
Saving to: '/Users/philip/Development/Node/ghost-0.7.8/static/index.html'
fixing links in /Users/philip/Development/Node/ghost-0.7.8/static/index.html
Traceback (most recent call last):
File "/usr/local/bin/buster", line 9, in <module>
load_entry_point('buster==0.1.3', 'console_scripts', 'buster')()
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/buster/buster.py", line 90, in main
newtext = fixLinks(filetext, parser)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/buster/buster.py", line 64, in fixLinks
d = PyQuery(bytes(bytearray(text, encoding='utf-8')), parser=parser)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquery/pyquery.py", line 226, in __init__
elements = fromstring(context, self.parser)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquery/pyquery.py", line 90, in fromstring
result = custom_parser(context)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/html/__init__.py", line 867, in fromstring
doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/html/__init__.py", line 752, in document_fromstring
value = etree.fromstring(html, parser, **kw)
File "src/lxml/lxml.etree.pyx", line 3213, in lxml.etree.fromstring (src/lxml/lxml.etree.c:82934)
File "src/lxml/parser.pxi", line 1819, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:124533)
File "src/lxml/parser.pxi", line 1707, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:123074)
File "src/lxml/parser.pxi", line 1079, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:117114)
File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:110510)
File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:112276)
File "src/lxml/parser.pxi", line 624, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:111367)lxml.etree.XMLSyntaxError: None
As stated in the comment, I did get in working however instead of just doing the 'Quick Install' recommended by many, I went the route of the 'Developer Install' guide here https://github.com/TryGhost/Ghost using the Stable branch.
After you run through that (with your local server running), in another terminal, run
$ buster setup
<Enter git repo>
$ buster generate --domain=localhost:2368
$ buster deploy (or as most sane people prefer, just git push)
Full instructions here: http://phil-a.github.io/getting-ghost-running-on-github-with-buster

Difference running python in PyCharm and in terminal

I'm wondering what is the difference when I run a python program from PyCharm or from the command line.
Actually I'm using a library called wand-py (ImageMagick binding).
If I run my program from the command line it works.
Though if I use PyCharm Run or debug it doesn't and I get the following traceback.
/Users/alexisbenoist/Documents/python/papyrus/env/bin/python "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py" --multiproc --client 127.0.0.1 --port 58993 --file /Users/alexisbenoist/Documents/python/papyrus/tets.py
Connected to pydev debugger (build 135.973)
pydev debugger: process 73166 is connecting
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py", line 1733, in <module>
debugger.run(setup['file'], None, None)
File "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py", line 1226, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/alexisbenoist/Documents/python/papyrus/tets.py", line 23, in <module>
blob = image_to_blob(PATH)
File "/Users/alexisbenoist/Documents/python/papyrus/tets.py", line 12, in image_to_blob
pdf.alpha_channel = False
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/image.py", line 419, in wrapped
result = function(self, *args, **kwargs)
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/image.py", line 992, in alpha_channel
self.raise_exception()
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/resource.py", line 218, in raise_exception
raise e
wand.exceptions.WandError: wand contains no images `MagickWand-1' # error/magick-image.c/MagickSetImageAlphaChannel/9504
I'm using the same virtual env in the terminal and PyCharm.
Do you guys know what could cause the problem?
Thanks,
Alexis.

portia (scrapy/slybot) errors on windows

i installed portia and got it to work i annotated some websites (looks really good)
but when i try to run the spiders i get some errors and nothing gets crawled
im running python 2.7.6 on win 7
C:\Python27\Scripts>python portiacrawl C:\portia\slyd\data\projects\new_project
Traceback (most recent call last):
File "portiacrawl", line 7, in <module>
execfile(__file__)
File "C:\portia\slybot\bin\portiacrawl", line 56, in <module>
main()
File "C:\portia\slybot\bin\portiacrawl", line 54, in main
subprocess.call(command_spec)
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] O sistema nÒo conseguiu localizar o ficheiro especificado
I am troubleshooting portia on Windows 8.1 and encountered the same error, exactly.
Try running 'python portiacrawl' by itself to determine if there is a subsequent menu. You should be able to see Help info on 'portiacrawl'. I suspect that you need to name the [spider] & [options] as well as change the terminal directory to see the output from the crawler. I suggest trying the following but rename [spider] to actual name of your spider w/o brackets:
Enter into terminal: C:\portia\slyd\data\projects <------Change to proper directory in cmd
Make sure you are in the terminal directory "C:\portia\slyd\data\projects"
The Cmd propmpt should look like: C:\portia\slyd\data\projects> <----waiting for portia initiation.
Enter into terminal:
python portiacrawl C:\portia\slyd\data\projects\new_project [spider] -t csv -o test.csv; or,
python portiacrawl [spider] -t csv -o test.csv
Report back. I am curious as to the terminal response. Did it initiate portiacrawl & return "access is denied."