I just started to use Python so the following might be a really REALLY dumb question but I searched the web for a long time and didn't find anything.
I'm trying to use the XMMS2 client from a Django View. Here is what I have in my views.py:
import xmmsclient
import os
import sys
def list(request):
xmms = xmmsclient.XMMS("tutorial1")
xmms.connect(os.getenv("XMMS_PATH"))
result = xmms.playlist_list_entries()
result.wait()
...
And here is the error I get:
AttributeError at /xmms2/list/
'module' object has no attribute 'XMMS'
And the line in question is this:
xmms = xmmsclient.XMMS("tutorial1")
The view works fine if I remove all the code and replace it with (for example):
return HttpResponse("list")
I first thought there was a problem with the xmmsclient library but it works fine when I run this xmms2-tutorial example
So I guess there is some sort of incompatibility between Django and xmmsclient but I really don't have a clue.
I'm running Ubuntu 12.04, Python 2.7.3, Django 1.4.1 and XMMS2 0.8
Any help will be really appreciated!
The problem was a name conflict. My Django app name was "xmmsclient".
So when I did
xmmsclient.XMMS("tut1")
I was referring to my app module, not the one from the XMMS2 client library.
Thanks a lot to Erik Massop from the xmms2-devel list!
Related
I tried to translate my web app with 'babel' but i trapped with the error:
"AttributeError: 'Babel' object has no attribute 'localeselector'"
I use python 3.11.1 and Babel 2.11.0
This is the code related to the problem.
from flask_babel import Babel, get_locale, gettext
#babel.localeselector
def determine_locale():
if 'language' in session:
return session['language']
return request.accept_languages.best_match(['en', 'es'])
I succssesfully created all the files like (messages.pot, messages.po and messages.mo) using command promt. I think I have poor knowlages about decorators themselves, and can't figure out where to look to find solution.
I tried to import localeselector using different ways, and read a lot of examples from peoples who did manage with it. But still can'n get the point what the step I've missed.
#babel.localeselector didn't work in my version of Flask and flask_babel. Use init_app instead:
babel.init_app(app, locale_selector=get_locale)
And make sure you defined get_locale() func before this call
See also Flask-Babel: get_locale() seems to be not working
I am three weeks into my independent study Python course, and am having trouble getting passed an issue. I am trying to use the function enterbox() from easygui I write:
import easygui
value = easygui.enterbox("say something")
And when I run it I get the error:
**AttributeError: 'module' object has no attribute 'enterbox'
Does anyone know why this may be happening? Thanks! (I'm using version 2.7)
It's been a while since I have used Python and am stumbling already at a simple import!
statements.py:
str = "hello"
main.py:
import statements
print statements.str
Obviously the final program will have more going on, and the statements will be stuff like URLs. For this simple example however with both files sitting side by side in the same folder I get the following error on running main.py:
AttributeError: 'module' object has no attribute 'str'
I know I am doing something terribly silly, but I can't see what it is. Searching around it looks fine. Any help/insight is appreciated.
You used the import statement correctly. The error then can be caused by either importing a different module with the same name, or by having altered the module after already having imported it.
You can check print statements.__file__ to see what module Python found instead when importing, and you can use the reload() function to ask Python to reload the module from disk if you altered it.
I am trying to follow this walkthrough on how to use the ServiceProxy in jsonrpc.
I followed the directions but I am getting an error no the import of the ServiceProxy.
Here is the code I am using:
#!usr/bin/python
import sys
import json
from jsonrpc import ServiceProxy
givex = jsonrpc.ServiceProxy()
print "foo"
which is resulting in:
Would anyone be able to help me out with some ideas on how to fix this, or have a suggestion for a better jsonrpc library to use.
The tutoral you are following seems to be outdated. Try
from jsonrpc.proxy import JSONRPCProxy
givex = JSONRPCProxy.from_url("http://localhost/url/of/your/service.py")
If you are trying to run this under Python 3.x, bear in mind that it is not yet supported. Many JSON RPC libraries have very similar names, but this particular one (jsonrpc without the dash, different from json-rpc or jsonrpc2) does not support Python 3 as of december 2016.
Here is the link for this particular library: https://pypi.python.org/pypi/jsonrpc
When I type this code into a python shell it works perfectly fine but within a program it gives an error.
import os
h = os.environ['HOME']
within a script it gives this error:
AttributeError: 'str' object has no attribute 'environ'
Why is this happening and is there any way I can fix it?
(I'm kinda just learning python so I dont know much. Google didn't help)
Somewhere, you've created a string and named it os. The . is the attribute lookup operator, so it's complaining about the thing to the left of the ., in this case, os.
are you sure that between import os and h = os.environ['HOME'] you did not use os as a variable for a string?
edit: If you do not work with an editor with a debugger (e.g. Eclipse with PyDev), try to find out from which point os is no longer a module by calling print(os) at some key points in your code