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

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.

Related

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.

Connection to AWS timed out using Python boto

I ran Python program in Cygwin to connect to AWS, but failed consistently as being timed out. But my connection to AWS using aws cli in Cygwin always works. Also if I run the same python code in Windows, it also works. I have checked all the connection credentials which are the same for all.
Here is the error msg:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 585, in get_all_instances
max_results=max_results)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 681, in get_all_reservations
[('item', Reservation)], verb='POST')
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1170, in get_list
response = self.make_request(action, params, path, verb)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1116, in make_request
return self._mexe(http_request)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1030, in _mexe
raise ex
socket.error: [Errno 116] Connection timed out
I have found out that the culprit lies in the proxy credentials.
I put HTTP_PROXY and HTTPS_PROXY as Windows Environment Variables. However, when run in Cygwin, boto uses 'http_proxy' to match without considering the case of the word
(see /boto/connection.py(669)handle_proxy()
line 669: if 'http_proxy' in os.environ and not self.proxy:).
When I changed the capital case HTTP_PROXY to lower case http_proxy, then it worked. Not sure why it isn't a problem if I run with Python in Windows.

Error while setting a django project on IIS

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

Error running django server from PyCharm with local settings file

I am trying to get my django server running from within PyCharm. I am able to start the server with no errors, but as soon as I browse to a page in the app I get the following error in the console:
pydev debugger: starting
Validating models...
0 errors found
Django version 1.4.10, using settings 'oneanddone.settings.local'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Users/bsilverberg/gitRepos/oneanddone/vendor/lib/python/django/contrib/staticfiles/handlers.py", line 67, in __call__
return self.application(environ, start_response)
File "/Users/bsilverberg/gitRepos/oneanddone/vendor/lib/python/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/Users/bsilverberg/gitRepos/oneanddone/vendor/lib/python/django/core/handlers/base.py", line 82, in get_response
urlconf = settings.ROOT_URLCONF
File "/Users/bsilverberg/gitRepos/oneanddone/vendor/lib/python/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
[09/Dec/2013 09:00:41] "GET /en-US/ HTTP/1.1" 500 59
I have a settings/local.py file and a settings/base.py file, and when I start the server from the terminal everything works fine. When starting from PyCharm I get the above error. My local settings file is getting loaded, as I can inspect the value of settings at this point in the code and can see my local values, but it seems like the settings from base.py are not being picked up (as that is where ROOT_URLCONF is defined).
So this doesn't seem to be an issue with DJANGO_SETTINGS_MODULE - it is finding the local.py file.
I'm running PyCharm 2.7.3 and django 1.4.
The most frustrating thing about this is that I had this working with a similar application a few months ago, and cannot figure out why it's not working now.
I just figured it out. All I had to do was point to the settings folder, instead of a specific file in the folder, and it all works.

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

Categories

Resources