I am trying to use the IMDbpy library in my django projects,but it raises an Attribute Error.
I tried all the solutions available on the internet,but none seem to work,could you please help me with this?
The Error:
moviesDB = imdb.IMDb()
AttributeError: module 'imdb' has no attribute 'IMDb'
The code:
import imdb
moviesDB = imdb.IMDb()
movies= moviesDB.search_movie('whatever_movie')
id = movies[0].getID()
movie = moviesDB.get_movie(id)
print(movie)
title=movie['title']
rating = movie['rating']
cover=movie['cover url']
print(title,rating,cover)
I have been scratching my head the entire day,due to this error,I'm kinda new to this,so please help!
I tried reinstalling the imdbpy library,pip3 installed it,renamed it but nothing seems to be working.
The code is working in external files,but in the views.py in django,it just doesnt seem to work
please help!
Try from imdb import IMDb then use IMDb() to initialize
Related
main.py :
import streamlit as st;
import Controllers.ClienteController as ClienteController
import models.Cliente as cliente
with st.form(key="include_client"):
input_name = st.text_input(label="Name")
input_age = st.number_input(label="Age", format= "%d", step=1)
input_occupation = st.selectbox(label="Select your occupation", options= ["Developer", "Engineer", "Doctor"])
input_button_submit = st.form_submit_button(label="Submit")
if input_button_submit:
cliente.name = input_name
cliente.age = input_age
cliente.occupation = input_occupation
ClienteController.Incluir(cliente)
Folder models: (models>cliente.py)
cliente.py :
class Cliente:
def __init__(self, name, age, occupation):
self.name = name
self.age = age
self.occupation = occupation
folder services : (services>database.py)
database.py :
import pyodbc
server = 'localhost'
database = 'crud'
username = ''
password = ''
cnxn = pyodbc.connect('DRIVER={ODBC Driver 18 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
folder Controllers : (Controllers>ClienteController.py)
ClienteController.py:
import services.database as db;
def Incluir(cliente):
count = db.cursor.execute("""
INSERT INTO crud (name, age, occupation)
VALUES (?,?,?)""",
cliente.name, cliente.age, cliente.occupation).rowcount
db.cnxn.commit()
When i run my streamlit and my main.py im getting this error :
File "C:\Users\h1ckzz\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 556, in _run_script
exec(code, module.__dict__)
File "C:\Users\h1ckzz\Desktop\CRUD\main.py", line 19, in <module>
ClienteController.Incluir(cliente)
AttributeError: module 'Controllers.ClienteController' has no attribute 'Incluir'
So when i press the button submit in my forms, this error shows up. Any solutions ?
A great help in debugging such type of problems is to check with:
print([e for e in dir(object) if e[0]!='_'])
which methods the object actually has. So you can see for example where you have a typo. Another advantage of this is that you check this way if what you think you have is actually there instead of assuming there is a problem with the software or the computer. The error message states clearly there is no Incluir in the imported module ... So the question is why don't you trust what the error message tells you? Because you think it can't be and there must be an issue with the system?
You can see in the comments:
To be clear, the code doesn't think Controllers.ClienteController has
an attribute Incluir. But your code shows that it does. Meaning... you
aren't running the code you think you are. You'll have to work on why.
– tdelaney
Just inject some print() and dir() statements into your code in order to see where your assumptions about what is going on are wrong.
And ... MAKE SURE you actually saved the code you have posted so the right code is imported. Not that you look at the right code, but in the file there is another one, with a typo.
As you see in the comments:
os.path.abspath(ClienteController.__file__)
would be interesting. And
if you are using jupyter or something, it may be a question of hitting
"save". – tdelaney
I am not alone with my suggestions.
At the end you will probably post the answer to your question yourself ... we are here only to help you in helping yourself with the ideas. The idea with __file__ is sure an interesting one and may reveal that you are importing another file from another directory as that one you think you are importing.
Thanks for everyone who helped me here.Really appreciate that help
I dont know why, but after a lot of search and print(), i found that the error was in the connection with SQL, that's why the code cant reached ControllersCliente even if the error not saying about that.
The solution for me :
pip unistall all the sql-connectors and install again
I am trying to export a tableau view as an image/csv (doesn't matter) using Python. I googled and found that REST API would help here, so I created a Personal Access Token and wrote the following command to connect: -
import tableauserverclient as TSC
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_views_dataframe, get_view_data_dataframe
server_url = 'https://tableau.mariadb.com'
site = ''
mytoken_name = 'Marine'
mytoken_secret = '$32mcyTOkmjSFqKBeVKEZYpMUexseV197l2MuvRlwHghMacCOa'
server = TSC.Server(server_url, use_server_version=True)
tableau_auth = TSC.PersonalAccessTokenAuth(token_name=mytoken_name, personal_access_token=mytoken_secret, site_id=site)
with server.auth.sign_in_with_personal_access_token(tableau_auth):
print('[Logged in successfully to {}]'.format(server_url))
It entered successfully and gave the message: -
[Logged in successfully to https://tableau.mariadb.com]
However, Iam at a loss now on how to access the tableau workbooks using Python. I searched here:-
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_workbooks_and_views.htm
but was unable to write these commands like GET or others in python.
Can anyone help?
I'm assuming you don't know the view_id of the view you're looking for
Adding this after the print in the with block will query all the views available on your site;
all_views, pagination_item = server.views.get()
print([view.name for view in all_views])
Then find the view you're looking for in the printed output and note the view_id for use like this;
view_item = server.view.get_by_id('d79634e1-6063-4ec9-95ff-50acbf609ff5')
From there, you can get the image like this;
server.views.populate_image(view_item)
with open('./view_image.png', 'wb') as f:
f.write(view_item.image)
The tableauserverclient-python docs should help you out a ton as well
https://tableau.github.io/server-client-python/docs/api-ref#views
I have importet the following modules.
import saxo_openapi
from saxo_openapi import API
import saxo_openapi.endpoints.referencedata as rd
with the class being
class saxo_openapi.endpoints.referencedata.exchanges.ExchangeList(params=None)
so in my code write the following:
r = rd.exchanges.ExhangeList()
rv = client.request(r)
print(json.dumps(rv.response, indent=4))
i have also tried various other ways of writing it, like:
client = saxo_openapi.API(access_token=...)
r = rd.ExchangeList()
client.request(r)
print(json.dumps(r.response, indent=4))
but i get the same error all the time. I cant figure out, what i am missing.
module 'saxo_openapi.endpoints.referencedata.exchanges' has no
attribute 'ExhangeList'
I really do hope you guys can help.
import flickrapi
api_key = "xxxxxx"
secret_api_key = "xxxxxxx"
flickr = flickrapi.FlickrAPI(api_key, secret_api_key)
def obtainImages():
photo_list = flickr.photos.search(api_key=api_key, has_geo=1, format='parsed-json', extras = 'tags')
for photo in photo_list[0]:
print photo.attrib['title']
obtainImages()
I want to import all images from flickr with a geo-tag, and I want to simply print the title out of these images for now. However I am getting an error saying "line 11, in obtainImages for photo in photo_list[0]: KeyError: 0"
I know its probably just a simple issue but any help in fixing it would be greatly appreciated! Thanks
I've been using the following code to try and create a new playlist in iTunes and a song from the main library - its example code i've found but i keep getting the following error when it runs. I've had a look through the iTunes COM interface documentation and it seems that AddTrack is only available under IITLibraryPlaylist but all of the example code Ive found is as below. Can anyone help>
Error: AttributeError: win32com.ge_py.iTunes 1.13 Type Library.IITPlaylist instance at 0x34035192 object has no attribute 'AddTrack'
Python Code:
import win32com.client
itunes = win32com.client.gencache.EnsureDispatch ("iTunes.Application")
mainLibrary = itunes.LibraryPlaylist
tracks = mainLibrary.Tracks
playlist = itunes.CreatePlaylist("Sonic Jams")
song = tracks.ItemByName('Teen Age Riot')
playlist.AddTrack(song)
in C#
Cast to IITUserPlayList
IITUserPlaylist rclibrary = (IITUserPlaylist)itunes.LibrarySource.Playlists.ItemByName["name"];
rclibrary.AddTrack(item);
i managed to get it using this code if anyone else needs it.
playlist = win32com.client.CastTo(itunes.CreatePlaylist("New List"), 'IITLibraryPlaylist')
song = tracks.ItemByName('Silver Rocket')
playlist.AddTrack(song)