I'm trying to run my Django application, which used to work fine before. Now, it is showing this strange error, which seems like coming from Django.
Django Version: 4.1
Python Version: 3.10.6 (Docker Image python:3.10.6)
django shell commands
Traceback (most recent call last):
File "/srv/project/./manage.py", line 9, in <module>
from django.core.management import execute_from_command_line
File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 16, in <module>
from django.apps import apps
File "/usr/local/lib/python3.10/site-packages/django/apps/__init__.py", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/django/apps/config.py", line 13, in <module>
File "/usr/local/lib/python3.10/site-packages/django/apps/config.py", line 62, in AppConfig
File "/usr/local/lib/python3.10/site-packages/django/utils/functional.py", line 27, in __init__
from django.utils.deprecation import RemovedInDjango50Warning
File "/usr/local/lib/python3.10/site-packages/django/utils/deprecation.py", line 5, in <module>
from asgiref.sync import sync_to_async
ValueError: source code string cannot contain null bytes
Related
I'm following along a course - Django development to deployment.
After pulling it to Digital Ocean everything else ran smoothly. Until
I tried running python manage.py help
(env) djangoadmin#ubuntu-1:~/pyapps/btre_project_4$ python manage.py help
and I get this error.
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/__init__.py", line 16, in setup
from django.urls import set_script_prefix
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/__init__.py", line 1, in <module>
from .base import (
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/base.py", line 9, in <module>
from .exceptions import NoReverseMatch, Resolver404
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/exceptions.py", line 1, in <module>
from django.http import Http404
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/__init__.py", line 2, in <module>
from django.http.request import (
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/request.py", line 10, in <module>
from django.core import signing
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/signing.py", line 45, in <module>
from django.utils.crypto import constant_time_compare, salted_hmac
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/utils/crypto.py", line 6, in <module>
import secrets
ImportError: No module named 'secrets'
I'm a newbie and have been stuck on this for a while. I just want to know what could possibly cause this.
The secrets module was added to Python in version 3.6. Your host is using Python 3.5, hence the secrets module is unavailable. You need a host with Python 3.6+, or a version of Django that doesn't depend on the secrets module
Had the same issue, solved it by specifying the python version I have installed. i.e
$ python3
>>> import secrets
>>> secrets.token_hex(16)
I am running into an error when importing the below library
from google.cloud import vision
The error message I receive is :
Traceback (most recent call last):
File "d:/UnmatchedOTMProcess/ImageDetection_test.py", line 2, in <module>
from google.cloud import vision
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-packages\google\cloud\vision.py", line
17, in <module>
from google.cloud.vision_v1 import ImageAnnotatorClient
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\cloud\vision_v1\__init__.py", line 27, in <module>
from google.cloud.vision_v1.gapic import image_annotator_client as iac
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\cloud\vision_v1\gapic\image_annotator_client.py", line 24, in <module>
import google.api_core.gapic_v1.client_info
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\api_core\gapic_v1\__init__.py", line 16, in <module>
from google.api_core.gapic_v1 import config
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-
packages\google\api_core\gapic_v1\config.py", line 23, in <module>
import grpc
File "C:\Users\mhancock\AppData\Roaming\Python\Python38\site-packages\grpc\__init__.py", line 23, in
<module>
from grpc._cython import cygrpc as _cygrpc
ImportError: cannot import name 'cygrpc' from 'grpc._cython'
(C:\Users\mhancock\AppData\Roaming\Python\Python38\site-packages\grpc\_cython\__init__.py)
The code works perfectly on my local machine, however trying to run this on a gcp virtual machine and the environment must be slightly different somehow.
Appreciate any assistance!
Thanks in advance,
Matt
Has anyone tried using newspaper3k python library on AWS Elastic Beanstalk Python 3.4?
I'm getting a strange error, despite images.py existing in the newspaper directory.
Traceback (most recent call last):
File "/opt/python/current/app/application.py", line 12, in <module>
from server.helper import get_connection, requires_auth, validate_schema, error_handler
File "/opt/python/current/app/server/helper.py", line 13, in <module>
from database.user import User
File "/opt/python/current/app/database/user.py", line 11, in <module>
from .post import Post
File "/opt/python/current/app/database/post.py", line 9, in <module>
from newspaper import Article
File "/opt/python/run/venv/lib/python3.4/site-packages/newspaper/__init__.py", line 10,in <module>
from .api import (build, build_article, fulltext, hot, languages,
File "/opt/python/run/venv/lib/python3.4/site-packages/newspaper/api.py", line 14, in <module>
from .article import Article
File "/opt/python/run/venv/lib/python3.4/site-packages/newspaper/article.py", line 14, in <module>
from . import images
ImportError: cannot import name 'images'
I have installed all dependencies (Pillow, lxml, libjpeg etc.) correctly and surprisingly when I ssh to instance it works properly.
Any help would be appreciated, thanks!
I have Windows 10, with Aptana Studio 3.
- I installed python in it (v.3.5.0) with terminal
- I installed scrapy 1.0
and now, if I try to run a crawler (scrapy) I get this message:
Traceback (most recent call last):
File "c:\python3.5\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "c:\python3.5\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python3.5\Scripts\scrapy.exe\__main__.py", line 5, in <module>
File "c:\python3.5\lib\site-packages\scrapy\__init__.py", line 48, in <module>
from scrapy.spiders import Spider
File "c:\python3.5\lib\site-packages\scrapy\spiders\__init__.py", line 10, in <module>
from scrapy.http import Request
File "c:\python3.5\lib\site-packages\scrapy\http\__init__.py", line 15, in <module>
from scrapy.http.response.html import HtmlResponse
File "c:\python3.5\lib\site-packages\scrapy\http\response\html.py", line 8, in <module>
from scrapy.http.response.text import TextResponse
File "c:\python3.5\lib\site-packages\scrapy\http\response\text.py", line 13, in <module>
from scrapy.utils.response import get_base_url
File "c:\python3.5\lib\site-packages\scrapy\utils\response.py", line 12, in <module>
from twisted.web import http
File "c:\python3.5\lib\site-packages\twisted\web\http.py", line 92, in <module>
from twisted.internet import interfaces, reactor, protocol, address
File "c:\python3.5\lib\site-packages\twisted\internet\reactor.py", line 38, in <module>
from twisted.internet import default
File "c:\python3.5\lib\site-packages\twisted\internet\default.py", line 56, in <module>
install = _getInstallFunction(platform)
File "c:\python3.5\lib\site-packages\twisted\internet\default.py", line 50, in _getInstallFunction
from twisted.internet.selectreactor import install
File "c:\python3.5\lib\site-packages\twisted\internet\selectreactor.py", line 18, in <module>
from twisted.internet import posixbase
File "c:\python3.5\lib\site-packages\twisted\internet\posixbase.py", line 18, in <module>
from twisted.internet import error, udp, tcp
File "c:\python3.5\lib\site-packages\twisted\internet\udp.py", line 53, in <module>
from twisted.internet import base, defer, address
File "c:\python3.5\lib\site-packages\twisted\internet\base.py", line 23, in <module>
from twisted.internet import fdesc, main, error, abstract, defer, threads
File "c:\python3.5\lib\site-packages\twisted\internet\defer.py", line 29, in <module>
from twisted.python import lockfile, failure
File "c:\python3.5\lib\site-packages\twisted\python\lockfile.py", line 52, in <module>
_open = file
NameError: name 'file' is not defined
So far I get that file() is a python 2.x function and it does not work with python 3.x from this Q: python NameError: name 'file' is not defined
But the problem is that I do not use file() anywhere in my script. And the message appears to reffer to scrapy default files. So what am I supposed to do? Edit the source files of scrapy? That sounds awfull and way above my knowledge level.
So what can I do?
I should install python 2.7 but for some reason (I don't remember) I could not install it properly when I tried
So anyone has a solution for this?
You likely need to update Twisted (to v15.4.0 or something similar), since your version is not Python 3 compatible.
As Matthias pointed out, scrapy is being ported to Python 3. However, the error you have is in lockfile.py from Twisted, not scrapy:
File "c:\python3.5\lib\site-packages\twisted\python\lockfile.py", line 52, in <module>
_open = file
Twisted is a dependency of scrapy. If you look at the history of this file, you'll see that there was a merge that presumably brought in Python 3 compatibility on 9/22/2015. I can tell that you have an older version because only the previous versions have _open = file in that lockfile.py.
All that being said, you probably still need to use Python 2 until the rest of scrapy is updated to be Py3 compatible.
It looks like scrapy is not yet fully ported to Python 3:
https://github.com/scrapy/scrapy/wiki/Python-3-Porting
So yes, use Python 2.
I'm trying to configure newrelic with zope but it is returning the error:
# bin/newrelic-admin run-python bin/zeoserver fg
Traceback (most recent call last):
File "bin/zeoserver", line 22, in <module>
import plone.recipe.zeoserver.ctl
File "/opt/bitnami/apps/plone/buildout-cache/eggs/plone.recipe.zeoserver-1.2.6-py2.7.egg/plone/recipe/zeoserver/__init__.py", line 9, in <module>
import zc.recipe.egg
File "/opt/bitnami/apps/plone/buildout-cache/eggs/zc.recipe.egg-1.3.2-py2.7.egg/zc/recipe/egg/__init__.py", line 1, in <module>
from zc.recipe.egg.egg import Egg, Scripts, Eggs
File "/opt/bitnami/apps/plone/buildout-cache/eggs/zc.recipe.egg-1.3.2-py2.7.egg/zc/recipe/egg/egg.py", line 21, in <module>
import zc.buildout.easy_install
File "/opt/bitnami/apps/plone/buildout-cache/eggs/zc.buildout-2.2.5-py2.7.egg/zc/buildout/easy_install.py", line 81, in <module>
pkg_resources.Requirement.parse('zc.buildout')).location,
AttributeError: 'NoneType' object has no attribute 'location'
Does anyone know what can it be pls?
I solved adding the below code in a __init__.py from application:
import newrelic.agent
newrelic.agent.initialize('path/of/newrelic.ini')
And execute the application without the command "newrelic-admin run-python".
Newrelic worked but with limitations because don't have official support yet.