I'm getting an error when I try to use a Django app and Python 3.7.
com_error at /polls/
(-2147024891, 'Access is denied.', None, None)
Request Method: GET
Request URL: http://192.1.1.100:80/polls/
Django Version: 2.2.6
Exception Type: com_error
Exception Value:
(-2147024891, 'Access is denied.', None, None)
Exception Location: C:\Python64\Python37\lib\site-packages\appdirs.py in _get_win_folder_with_pywin32, line 481
Python Executable: C:\Python64\Python37\python.exe
Python Version: 3.7.4
Python Path:
['.',
'C:\\inetpub\\wwwroot\\Pounce',
'C:\\Python37\\python37.zip',
'C:\\Python37\\DLLs',
'C:\\Python37\\lib',
'C:\\Python37',
'C:\\Python37\\lib\\site-packages',
'C:\\Python37\\lib\\site-packages\\win32',
'C:\\Python37\\lib\\site-packages\\win32\\lib',
'C:\\Python37\\lib\\site-packages\\Pythonwin']
The app had been working fine over the past year. This is the first time I'm getting this error. I recently installed pypiwin32. Otherwise everything is the same.
Related
I am trying to write an ansible playbook to crawl a website and then store its contents into a static file under aws s3 bucket. Here is the crawler code :
"""
Handling pages with the Next button
"""
import sys
from urllib.parse import urljoin
import requests
from bs4 import BeautifulSoup
url = "https://xyz.co.uk/"
file_name = "web_content.txt"
while True:
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
raw_html = soup.prettify()
file = open(file_name, 'wb')
print('Collecting the website contents')
file.write(raw_html.encode())
file.close()
print('Saved to %s' % file_name)
#print(type(raw_html))
# Finding next page
next_page_element = soup.select_one('li.next > a')
if next_page_element:
next_page_url = next_page_element.get('href')
url = urljoin(url, next_page_url)
else:
break
This is my ansible-playbook:
---
- name: create s3 bucket and upload static website content into it
hosts: localhost
connection: local
tasks:
- name: create a s3 bucket
amazon.aws.aws_s3:
bucket: testbucket393647914679149
region: ap-south-1
mode: create
- name: create a folder in the bucket
amazon.aws.aws_s3:
bucket: testbucket393647914679149
object: /my/directory/path
mode: create
- name: Upgrade pip
pip:
name: pip
version: 21.1.3
- name: install virtualenv via pip
pip:
requirements: /root/ansible/requirements.txt
virtualenv: /root/ansible/myvenv
virtualenv_python: python3.6
environment:
PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin"
- name: Run script to crawl the website
script: /root/ansible/beautiful_crawl.py
- name: copy file into bucket folder
amazon.aws.aws_s3:
bucket: testbucket393647914679149
object: /my/directory/path/web_content.text
src: web_content.text
mode: put
Problem is when I run this, it runs fine upto the task name: install virtualenv via pip and then throws following error while executing the task name: Run script to crawl the website:
fatal: [localhost]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 2, "stderr": "/root/.ansible/tmp/ansible-tmp-1625137700.8854306-13026-9798 3643645466/beautiful_crawl.py: line 1: import: command not found\n/root/.ansible /tmp/ansible-tmp-1625137700.8854306-13026-97983643645466/beautiful_crawl.py: lin e 2: from: command not found\n/root/.ansible/tmp/ansible-tmp-1625137700.8854306- 13026-97983643645466/beautiful_crawl.py: line 3: import: command not found\n/roo t/.ansible/tmp/ansible-tmp-1625137700.8854306-13026-97983643645466/beautiful_cra wl.py: line 4: from: command not found\n/root/.ansible/tmp/ansible-tmp-162513770 0.8854306-13026-97983643645466/beautiful_crawl.py: line 6: url: command not foun d\n/root/.ansible/tmp/ansible-tmp-1625137700.8854306-13026-97983643645466/beauti ful_crawl.py: line 7: file_name: command not found\n/root/.ansible/tmp/ansible-t mp-1625137700.8854306-13026-97983643645466/beautiful_crawl.py: line 10: syntax e rror near unexpected token ('\n/root/.ansible/tmp/ansible-tmp-1625137700.885430 6-13026-97983643645466/beautiful_crawl.py: line 10: response = requests.get (url)'\n", "stderr_lines": ["/root/.ansible/tmp/ansible-tmp-1625137700.8854306-1 3026-97983643645466/beautiful_crawl.py: line 1: import: command not found", "/ro ot/.ansible/tmp/ansible-tmp-1625137700.8854306-13026-97983643645466/beautiful_cr awl.py: line 2: from: command not found", "/root/.ansible/tmp/ansible-tmp-162513 7700.8854306-13026-97983643645466/beautiful_crawl.py: line 3: import: command no t found", "/root/.ansible/tmp/ansible-tmp-1625137700.8854306-13026-9798364364546 6/beautiful_crawl.py: line 4: from: command not found", "/root/.ansible/tmp/ansi ble-tmp-1625137700.8854306-13026-97983643645466/beautiful_crawl.py: line 6: url: command not found", "/root/.ansible/tmp/ansible-tmp-1625137700.8854306-13026-97 983643645466/beautiful_crawl.py: line 7: file_name: command not found", "/root/. ansible/tmp/ansible-tmp-1625137700.8854306-13026-97983643645466/beautiful_crawl. py: line 10: syntax error near unexpected token ('", "/root/.ansible/tmp/ansibl e-tmp-1625137700.8854306-13026-97983643645466/beautiful_crawl.py: line 10: response = requests.get(url)'"], "stdout": "", "stdout_lines": []}
What am I doing wrong here?
You have multiple problems.
Check the documentation.
No. 1: The script modules will run bash scripts by default, not python scripts. If you want to run a python script, you need to add a shebang like #!/usr/bin/env python3 as the first line of the script or use the executable parameter.
No 2: You create a venv, so I assume you want to run the script in that venv. You can't do that out of the box with the script module, so you would need to work around that.
This should work for you (you don't need the shebang, as you tell the script module to run it with python in the venv using the executable parameter):
- name: Run script to crawl the website
script: /root/ansible/beautiful_crawl.py
executable: /root/ansible/myvenv/bin/python
My setup is Windows 10, Python 3.7, Apache 2.4/mod_wsgi. When I add this enctype="multipart/form-data" in my form (just by adding this attribute, only -- no files are attached to the form) I get this error when submitting:
Django Version: 1.8.5
Exception Type: RuntimeError
Exception Value: generator raised StopIteration
Exception Location: c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py in read, line 337
Python Executable: C:\Apache24\bin\httpd.exe
Python Version: 3.7.3
My Django code is this:
elif request.method == "POST":
rid = request.POST.get("recipe", "")
title = request.POST.get("title")
content = request.POST.get("content")
tag_names = request.POST.getlist("tags")
image = request.FILES.get("image")
if rid:
recipe = get_object_or_404(FoodRecipe, pk=rid)
else:
recipe = FoodRecipe.objects.create(title=title)
recipe.content = content
recipe.title = title
if image:
recipe.featured = image
for tn in tag_names:
tag, cr = Tag.objects.get_or_create(
name=tn
)
recipe.tags.add(tag)
recipe.save()
And this is full traceback:
Environment:
Request Method: POST
Request URL: http://192.168.1.250/recipes/add/
Django Version: 1.8.5
Python Version: 3.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tinymce',
'sekizai',
'sorl.thumbnail',
'recipes',
'guides',
'inbox',
'appdata',
'account',
'customer',
'core')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'account.middleware.PasswordChangeMiddleware.PasswordChangeMiddleware')
Traceback:
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\core\handlers\base.py" in get_response
125. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\middleware\csrf.py" in process_view
174. request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\core\handlers\wsgi.py" in _get_post
137. self._load_post_and_files()
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\request.py" in _load_post_and_files
260. self._post, self._files = self.parse_file_upload(self.META, data)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\request.py" in parse_file_upload
225. return parser.parse()
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in parse
149. for item_type, meta_data, field_stream in Parser(stream, self._boundary):
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in __iter__
628. yield parse_boundary_stream(sub_stream, 1024)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in parse_boundary_stream
567. chunk = stream.read(max_header_size)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in read
337. out = b''.join(parts())
Exception Type: RuntimeError at /recipes/add/
Exception Value: generator raised StopIteration
Any ideas what is going wrong?
PS: Same django application worked fine in Linux/Nginx/Gunicorn/Python2.7 setup. So, I guess it must some misconfiguration between Django/Python/Apache.
Your Django is very old and you need to update. This is a Python 3.7 compatibility problem that the Django devs already fixed four years ago, back when it was just a PendingDeprecationWarning on Python 3.5.
In fact, you are on the very last Django version that doesn't have the fix. Even 1.8.6 has the fix.
Firstly I call:
from django.contrib.auth import views as auth_views
After that I have set the url:
path('reset_password/',auth_views.PasswordResetView.as_view(),name='reset_password'),
When I run the url the key error raised.
Request Method: GET
Request URL: http://127.0.0.1:8000/user/reset_password/
Django Version: 3.1
Exception Type: KeyError
Exception Value:
'available_apps'
Exception Location: C:\Users\Syed Mithu\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\context.py, line 83, in __getitem__
Python Executable: C:\Users\Syed Mithu\AppData\Local\Programs\Python\Python38\python.exe
Python Version: 3.8.3
Python Path:
['F:\\12.05.2021\\Project\\Music_E-com',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
'C:\\Users\\Syed Mithu\\AppData\\Local\\Programs\\Python\\Python38\\DLLs',
'C:\\Users\\Syed Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib',
'C:\\Users\\Syed Mithu\\AppData\\Local\\Programs\\Python\\Python38',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\win32',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\win32\\lib',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\Pythonwin']
Server time: Thu, 20 May 2021 06:51:41 +0000
Project Details:
Was generated with Jhipster 4.3.0
Now, SpringBoot version upgraded from 1.5.2 to 2.2.6
After SpringBoot version upgrade, Administration>Metrics does not work.
Application.yml -Metrics
management:
server:
servlet:
context-path: /management
endpoints:
web:
base-path: /management
exposure:
include: ['configprops', 'env', 'health', 'info', 'metrics', 'jhimetrics', 'logfile', 'loggers', 'prometheus', 'threaddump']
endpoint:
jhimetrics:
enabled: true
metrics:
enable:
http: true
jvm: true
logback: true
process: true
system: true
On hitting http://localhost:8080/management/metrics, I am getting following response:
{"names":[
"cache.removals",
"http.server.requests",
"cache.evictions",
"cache.gets",
"process.start.time",
"cache.puts",
"http.server.requests.percentile",
"jvm.threads.states",
"jvm.memory.committed",
"jdbc.connections.active",
"jvm.gc.memory.promoted",
"jvm.memory.max",
"jvm.gc.pause.percentile",
"jvm.gc.max.data.size",
"jvm.gc.pause",
"jdbc.connections.max",
"jdbc.connections.min",
"system.cpu.count",
"logback.events",
"jvm.memory.used",
"jvm.threads.daemon",
"jvm.buffer.memory.used",
"system.cpu.usage",
"jvm.gc.memory.allocated",
"jdbc.connections.idle",
"jvm.threads.live",
"jvm.threads.peak",
"process.uptime",
"process.cpu.usage",
"jvm.classes.loaded",
"jvm.classes.unloaded",
"jvm.gc.live.data.size",
"jvm.buffer.count",
"jvm.buffer.total.capacity"]}
While I am expecting response like this:
I also tried to hit http://localhost:9999/management/jhimetrics, here I got 404 error.
Anyone encountered similar problem or any has solution? Please help.
I set up a very simple project to try out Haystack using a Whoosh engine, mostly following the example in the documentation. I installed everything using pip and no version numbers, so I should have the latest release versions.
I'm getting this error and I have no idea what I'm supposed to do now, I cannot find anything similar though I've scoured Google. Please help!
The project folder structure is very simple, with one app called cat.
project
|-cat
| |-migrations
| |-admin.py, apps.py, models.py, search_indexes.py
|-templates
| |-search
| |-indexes
| | |-cat
| | |-cat_text.txt
| |-search.html
|-manage.py, settings.py, urls.py
The error I'm getting is:
Environment:
Request Method: GET
Request URL: http://localhost:8000/search/?q=felix&models=cat.cat
Django Version: 1.9.4
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'haystack',
'cat',]
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/haystack/views.py" in __call__
51. self.results = self.get_results()
File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/haystack/views.py" in get_results
91. return self.form.search()
File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/haystack/forms.py" in search
116. return sqs.models(*self.get_models())
File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/haystack/forms.py" in get_models
110. search_models.append(models.get_model(*model.split('.')))
Exception Type: AttributeError at /search/
Exception Value: 'module' object has no attribute 'get_model'
models.py:
class Cat(models.Model):
name = models.CharField(max_length=255)
birth_date = models.DateField(default=datetime.date.today)
bio = models.TextField(blank=True)
created = models.DateTimeField(default=datetime.datetime.now)
updated = models.DateTimeField(default=datetime.datetime.now)
def __unicode__(self):
return self.name
#models.permalink
def get_absolute_url(self):
return ('cat_detail', [], {'id': self.id})
search_indexes.py
class CatIndex(indexes.BasicSearchIndex, indexes.Indexable):
def get_model(self):
return Cat
For anyone else struggling with this, this is all due to a little change in Django 1.9, in which the get_model() method is moved to the django.apps.apps module, and is no longer available from django.db
The issue is resolved now in Haystack community, so updating to the newest version, from their GitHub repository (and not PyPI) must solve it.
The following should solve it:
pip install git+https://github.com/django-haystack/django-haystack.git
Or you can simply downgrade to Django 1.8 as Sam suggested.
You can find more over this issue here
Solution: downgrade Django from 1.9 to 1.8
sudo pip install Django==1.8
Motivations here: link