Cherrypy json_out module error in Ubuntu - python

I am trying to get Cherrypy to output json for a project and on my Mac adding the #cherrpy.tools.json_out() decorator is working a treat but on my Ubuntu 13.04 system I get this error.
Traceback (most recent call last):
File "cherrypy.py", line 1, in <module>
import cherrypy
File "/bla/cherrypy.py", line 4, in <module>
class Root(object):
File "/bla/cherrypy.py", line 6, in Root
#cherrypy.tools.json_out()
AttributeError: 'module' object has no attribute 'tools'
The code above is a direct copy from the bottom of this page.
http://tools.cherrypy.org/wiki/JSON
If i enter a python shell then run interactive help on the module I get a similar result.
help> cherrypy
problem in cherrypy - <type 'exceptions.AttributeError'>: 'module' object has no attribute 'tools'
I have tried searching but I can't find anyone else having the same issue? (Maybe I am missing the wood for the trees?)
I have tried reinstalling the package through apt and manually from the cherrypy source all against Python 2.7
Although I am developing on Mac and Ubuntu I will be deploying on an Ubuntu server so I would like to sort this out sooner rather than later.
Your help is much appreciated

Do you use python-cherrypy from ubuntu package? It's version is 2.3.0 which does not have cherrypy.tools modules.
Install newer version (sudo pip install -U cherrypy).

Related

Can't run Python 3, io.py gives a AttributeError on Windows 10

I tried to run Python3 on my Windows but it gives me a AttributeError from io.py.
I have tried both the Windows Store version and Download from https://www.python.org/downloads/
When I try to run python3 or py in PowerShell 7.2.6 terminal I get
PS>python3
>Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
File "C:\Program\Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\io.py", line 87, in <module>
AttributeError: module 'abc' has no attribute 'ABCMeta'
or
PS>py
>Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
File "C:\Users\UserName\AppData\Local\Programs\Python\Python310\lib\io.py", line 87, in <module>
AttributeError: module 'abc' has no attribute 'ABCMeta'
With troubleshooting I have tried a few things
To reinstall both from the Windows Store and the Download from https://www.python.org/downloads/, but it doesn't seem to resolve the problem.
Only run the store version or the download from the website.
I have tried to troubleshoot on the internet, but I don't see anything when it comes to running Python alone. And usually comes down to naming Python scripts which I don't want to run specificly.
I thought it could be a systen PATH problem in Windows, but that seems to be not the case as it still didnt work after I changed the path to "C:\Users\UserName\AppData\Local\Programs\Python\Python310" and "C:\Users\UserName\AppData\Local\Programs\Python\Python310\Scripts".
And the problem seems to come from the io.py which can't see the attribute ABCMeta from the module abc.
How can I solve this problem?

codeanywhere.com Python doesn't see virtualenv

I use codeanywhere.com try to create application with Python werkzeug and jinja2.
I install those library utilize virtualenv. Now I face the problem
Traceback (most recent call last):
File "manage.py", line 4, in
from werkzeug import Request
ImportError: No module named 'werkzeug'
virtualenv activated but nothing is works.
Does anybody has experience with codeanywhere.com?
Oh I solve this problem. In the container config file add instruction "source venv3/bin/activate" as shown on a picture add path to python as well.
enter image description here

ssl using flask and python3, works on Ubuntu but not Mac

I had the issue on Ubuntu (14.04) on AWS but resolved it by upgrading my Python to 3.4.3 (from 2.7). However, I still get the issue locally (Mac Yosemite, v10.10.5) even though Ive upgraded my python. The error is:
Traceback (most recent call last):
File "payment_app.py", line 97, in <module>
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'
My Python version (python3 --version) on my Mac is:
Python 3.4.4
Is there any differences between Mac:s version of Python and Ubuntu:s? If so, how to I handle this error?
Thanks in advance.
Peter

Python 3.4 is missing _ssl.pyd

Environment:
Ubuntu 10.04.4 LTS
Python 3.4.3
I have a working python 3.4 Flask HTTPS server running perfectly on Windows. I need to transfer this over to an existing Ubuntu 10.04.4 LTS server. I have built python 3.4 on there with no problems but when I run my web server it fails with the error:
Traceback (most recent call last):
File "./server.py", line 3, in <module>
from app import create_app
File "/opt/license-server/app/__init__.py", line 10, in <module>
from config import config
File "/opt/license-server/config.py", line 9, in <module>
class Config:
File "/opt/license-server/config.py", line 25, in Config
LDAP_TLS_VERSION = ssl.PROTOCOL_TLSv1_2
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'
I did some digging around on Windows using pyCharm to find out what is going on and it seems that PROTOCOL_TLSv1_2 is defined in _ssl.py which I believe comes from _ssl.pyd. Neither _ssl.py or _ssl.pyd exists on the Ubuntu python install which leads me to believe that I'm missing some option or something when compiling but I cannot find any reference to this on the python web site on what is missing or how to get the TLS-1.2 stuff.
Can anyone point me in the right direction please?
When you build your Python 3.4 from sources, at the end of the build you get a report saying which modules were not built. My bet is that the ssl module was not build, because your Ubuntu installation doesn't have SSL packages installed. Try:
sudo apt-get install libssl-dev openssl
then try to rebuild your Python 3.4 and see if the SSL module is built.

'module' object has no attribute 'Twitter'

I am trying to follow the example on page 5 of the book: Mining the Social Web, from O'Reilly. I am coming across the following error:
>>> import twitter
>>> twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'Twitter'
What might be going on?
Check the value of twitter.__file__ (after you've imported twitter). My guess is either you somehow got a broken version of twitter, or you've created a file called twitter.py in the same directory you're running from that's blocking the installed module from loading.
If twitter.__file__ looks good (points to where your installed modules should be instead of the local dir), try easy_install -U twitter to reinstall it.
Works for me. I installed twitter through easy_install, which installed the latest version (1.6.1). dir(twitter) also lists Twitter here.
You could remove the twitter package from site-packages and try reinstalling again.

Categories

Resources