Error while setting a django project on IIS - python

I was following these steps for setting up django on IIS8. I got till the end of the documentation but when i ran the localhost on port 8003, i was getting the following error:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "C:\inetpub\wwwroot\Django\[myprojname]\wfastcgi.py", line 710, in main
env, handler = read_wsgi_handler(response.physical_path)
File "C:\inetpub\wwwroot\Django\[myprojname]\wfastcgi.py", line 567, in read_wsgi_handler
return env, get_wsgi_handler(handler_name)
File "C:\inetpub\wwwroot\Django\[myprojname]\wfastcgi.py", line 538, in get_wsgi_handler
handler = getattr(handler, name)
AttributeError: 'module' object has no attribute 'wsgi'
StdOut:
StdErr:
Can anyone let me know why it wouldn't give me the same output as shown in the tutorial?

Apparently pip install django does not set the proper permissions for IIS to use the libraries it downloaded.
You need to find your Python folder (C:\python27 by default) and forcibly reset the permissions, i.e. Replace all child object permissions with inheritable permissions from this object as shown here:
https://serverfault.com/questions/475612/replace-permission-entries-on-all-child-objects-using-icacls

Related

os.environ producing error recently only?

Recently I had this problem with vscode where os.environ isn't working anymore, it used to be able to read the key on the separate .env file. This file works perfect on replit, however, when i try downloading it, it can't be run locally
I have tried deleting .pyc files, but it's still the same.
Python os.environ throws key error?
Error in the terminal:
Traceback (most recent call last):
File "c:\Users\heroku\Desktop\ricebot\main.py", line 62, in <module>
my_secret = os.environ['TOKEN']
File "C:\Users\heroku\AppData\Local\Programs\Python\Python39\lib\os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'TOKEN'

Django,IIS. I can't publish django using IIS

I'm trying to publish django using Microsoft IIS. I got an error when accessing http://localhost. Django version is 3.1.7 and python is 3.9.2, windows server 2019.
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "c:\program files\python39\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "c:\program files\python39\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "c:\program files\python39\lib\site-packages\wfastcgi.py", line 603, in get_wsgi_handler
handler = getattr(handler, name)
AttributeError: module 'django.core' has no attribute 'wsgi'
StdOut:
StdErr:
There are many reasons for this error, you can try below methods to solve this error:
In your Django project, there is a init.py file, remove it and try again.
Try to find your Python folder (C:\python27 by default) and forcibly reset the permissions, i.e. Replace all child object permissions with inheritable permissions from this object as shown here: https://serverfault.com/questions/475612/replace-permission-entries-on-all-child-objects-using-icacls
If the problem cannot be solved, please share your project path and Web.config file.

Site-packages error in CKAN connected to ckanext-showcase

I have installed a CKAN Instance and I have installed the ckanext-showcase module.
Although the installation didn't raise any errors and I was able to add a few showcases when some of my users that I had set as showcase administrators started adding showcases the module has stopped working.
The page {portal.url/showcase} can't be viewed unless I am connected as system administrator. When a user or even a showcase user tries to enter the page get's an internal server error.
From that point on when I am trying to create a new system administrator from console with the paster command (http://docs.ckan.org/en/latest/maintaining/getting-started.html#create-admin-user) I get the bellow message
Traceback (most recent call last):
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 703, in
main()
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 683, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 282, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 204, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 173, in addpackage
exec(line)
File "", line 1, in
KeyError: 'ckanext'
Because I don't have the ability to install the CKAN again right now, is there any suggestions on how I to fix this?
Any help would be greatly appreciated
After looking to my server error logs I found that the error wasn't caused by the plugin ckanext-showcase but from the module ckanext-datarequests.
The first part of my problem was connected to a server error coming at a 401 Unauthorized exception not being handled at version 1.0.2 of the plugin. As soon as I upgraded to the latest version 1.0.3 the error was fixed.

Python ImportError: No module named - Works in ssh but not in browser

Not sure what the issue is. Works fine via ssh. When viewed in a browser I get a server error. This is know working code that has been migrated to another server / environment.
It can not find a module that is clearly in the directory. Have checked permissions on files and they look ok 755.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
ImportError: No module named xmlproducts
mod_python (pid=16232, interpreter='realtechy.com', phase='PythonHandler', handler='mod_python.cgihandler'): Application error
ServerName: 'realtechy.com'
DocumentRoot: '/var/www/vhosts/realtechy.com/httpdocs'
URI: '/products/myproducts.py'
Location: None
Directory: '/var/www/vhosts/realtechy.com/httpdocs/'
Filename: '/var/www/vhosts/realtechy.com/httpdocs/products/myproducts.py'
PathInfo: ''
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line 1229, in _process_target\n result = _execute_target(config, req, object, arg)
File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line 1128, in _execute_target\n result = object(arg)
File "/usr/lib/python2.6/site-packages/mod_python/cgihandler.py", line 96, in handler\n imp.load_module(module_name, fd, path, desc)
File "/var/www/vhosts/realtechy.com/httpdocs/products/myproducts.py", line 6, in <module>\n import xmlproducts
ImportError: No module named xmlproducts
Sounds like the module is not installed properly (or at all). To verify, do the following:
open a shell and start the python shell by typing python
enter the commmand help('modules')
review the list of modules that's returned to see whether xmlproducts is included
if not, then install the module

Why does web2py crash for me upon startup?

I"m trying to get web2py running on an Ubuntu machine. All the docs seem to indicate that to run it on a *nix system, you download the source and do:
python web2py.py
I grabbed the source (stable source, not the trunk, version 1.99.4) and tried the above, but after entering a password for the server I get (in the terminal):
$ python web2py.py
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2011
Version 1.99.4 (2011-12-14 14:46:14) stable
Database drivers available: google
Starting hardcron...
WARNING:web2py.cron:WEB2PY CRON: Disabled because no file locking
please visit:
http://127.0.0.1:8000
starting browser...
failed to create drawable
DEBUG: connect attempt 0, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
WARNING:web2py.cron:WEB2PY CRON: Disabled because no file locking
DEBUG: connect attempt 1, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
DEBUG: connect attempt 2, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
DEBUG: connect attempt 3, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
DEBUG: connect attempt 4, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
And then in the browser I get:
Internal error
Ticket issued: welcome/127.0.0.1.2012-.....[abbreviated]
Any suggestions? I'm running Python 2.7.1+. I've read elsewhere that you also need pyschopg2 installed for web2py to run, and I've confirmed that this is in fact installed as well (I did a sudo apt-get install python-psycopg2 and got "python-psycopg2 is already the newest version").
I just downloaded and web2py runs ok in ubuntu, python 2.7.2+
bruce#vaiubuntu:~/Downloads/web2py$ python web2py.py
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2011
Version 1.99.4 (2011-12-14 14:46:14) stable
Database drivers available: SQLite3, pymysql, PostgreSQL
Starting hardcron...
Are you trying to run web2py on appengine environment?
Do you have SQLITE module working ok in your Python?
A possibility is permission issue, your user have permission to write to web2py/* folder?
It looks like a bug in web2py 1.99.4. I was having the same problem using Postgres and psycopg2, but in Windows.
I tried with 1.99.2 and it worked fine.
Actually, the bug seems to be related to the cryptic error message - 1.99.2 gave me the error message that the database doesn't exist, which was easily fixed. 1.99.4 does not mention the missing database. However, when I created the database and tried with 1.99.4, it worked fine.

Categories

Resources