Installed imdbpy and tried running the default examples mentioned on -http://imdbpy.sourceforge.net/support.html, but I am unable to run them successfully.
Program:
# Create the object that will be used to access the IMDb's database.
ia = imdb.IMDb() # by default access the web.
# Search for a movie (get a list of Movie objects).
s_result = ia.search_movie('The Untouchables')
# Print the long imdb canonical title and movieID of the results.
for item in s_result:
print item['long imdb canonical title'], item.movieID
# Retrieves default information for the first result (a Movie object).
the_unt = s_result[0]
ia.update(the_unt)
# Print some information.
print the_unt['runtime']
print the_unt['rating']
director = the_unt['director'] # get a list of Person objects.
# Get the first item listed as a "goof".
ia.update(the_unt, 'goofs')
print the_unt['goofs'][0]
# The first "trivia" for the first director.
b_depalma = director[0]
ia.update(b_depalma)
print b_depalma['trivia'][0]
Error:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/karan/PycharmProjects/IMDBParser/extractor/imdbpy_tester.py
Untouchables, The (1987) 0094226
Untouchables (in development), The (????) 1987680
"Untouchables, The" (1959) 0052522
"Untouchables, The" (1993) 0106165
Intouchables, The (2011) 1675434
Untouchables, The (2017) 1877895
Untouchable (I) (2016) 5509634
Untouchable 2, The (2001) (VG) 0287778
"Untouchable" (2015) 4191792
Untouchable, The (1997) (VG) 0287779
Untouchable (2012) 2266916
"Untouchable" (2017) (mini) 5220680
Untouchable (I) (2010) 1590231
Untouchable (III) (2013) 3001590
Untouchables, The (1991) (VG) 0335509
"Frontline" The Untouchables (2013) 2620144
"DVD_TV: Enhanced Version" The Untouchables (2005) 1088289
"Real Story, The" The Untouchables (2009) 2760176
"Harbour Lights" The Untouchables (1999) 0596815
"Bill, The" The Untouchables (2000) 0525783
[u'119']
7.9
Traceback (most recent call last):
File "/Users/karan/PycharmProjects/IMDBParser/extractor/imdbpy_tester.py", line 27, in <module>
print the_unt['goofs'][0]
File "/Library/Python/2.7/site-packages/IMDbPY-5.0-py2.7-macosx-10.11-intel.egg/imdb/utils.py", line 1469, in __getitem__
rawData = self.data[key]
KeyError: 'goofs'
Process finished with exit code 1
I found sth similar posted by another user here - https://bitbucket.org/alberanid/imdbpy/issues/42/examples-not-functional but I do not know how to fix this problem.
Related
Oh my python guys, please help me.
One of my python projects suddenly stopped working for no reason.
I'm using pytube module and when i try to run the code i get this error:
Traceback (most recent call last):
File "C:\Users\giova\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\contrib\search.py", line 94, in fetch_and_parse
sections = raw_results['contents']['twoColumnSearchResultsRenderer'][
KeyError: 'twoColumnSearchResultsRenderer' fetch_and_parse
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\giova\OneDrive\Desktop\Coding\Python\youtubeapp.py", line 38, in <module>
videoSearch()
File "C:\Users\giova\OneDrive\Desktop\Coding\Python\youtubeapp.py", line 21, in videoSearch
availableResults = len(vid.results)
File "C:\Users\giova\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\contrib\search.py", line 62, in results
videos, continuation = self.fetch_and_parse() results
File "C:\Users\giova\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\contrib\search.py", line 97, in fetch_and_parse fetch_and_parse
sections = raw_results['onResponseReceivedCommands'][0][
KeyError: 'onResponseReceivedCommands'
This is not even the only error i get, sometimes i got "http error 410: gone" error or some like this. I haven't changed the code for about two weeks (it was working two weeks ago) and it stopped working. I don't know what is happening to my code.
This is the full code:
from pytube import Search, YouTube
print("================================\n What do you want to do?: ")
availableChoose = [
'1 Search videos',
'...',
'================================'
]
for choose in availableChoose:
print(choose)
userChoose = input()
userChoose = userChoose.lower()
def videoSearch():
userSearch = input("Enter the title of the video you want to search: ")
vid = Search(userSearch)
availableResults = len(vid.results)
strAvailableResults = str(availableResults)
print("The available results are " + strAvailableResults)
vidResultsList = vid.results
vidResultsList = str(vidResultsList)
vidResultsList = vidResultsList.replace("<pytube.__main__.YouTube object: videoId=", "")
vidResultsList = vidResultsList.replace(">", "")
vidResultsList = vidResultsList.replace("[", "")
vidResultsList = vidResultsList.replace("]", "")
vidResultsList = vidResultsList.replace(" ", "")
vidResultsList = vidResultsList.split(',')
for vidResultsObject in vidResultsList:
vidLink = ("https://www.youtube.com/watch?v=" + vidResultsObject)
vidTempObject = YouTube(vidLink)
print(vidTempObject.title + " - " + vidLink)
if(userChoose == "search" or userChoose == "search video" or userChoose == "search videos" or userChoose == "1"):
videoSearch()
pytube's 11.0.0 API docs list the Search.fetch_and_parse() method.
The corresponding source-code shows that it internally handles a KeyError for onResponseReceivedCommands:
# Initial result is handled by try block, continuations by except block
try:
sections = raw_results['contents']['twoColumnSearchResultsRenderer'][
'primaryContents']['sectionListRenderer']['contents']
except KeyError:
sections = raw_results['onResponseReceivedCommands'][0][
'appendContinuationItemsAction']['continuationItems']
This method is an inner one, that is used by your vid.results call.
Might be, that the Youtube API has changed there response and your version of pytube is not fitting anymore.
Bug already filed
See pytube issue #1082 and issue #1106.
Meanwhile use another branch
tfdahlin's fork has a bugfixed version. It was already proposed as Pull-Request to the project:
PR #1090, opened on 2021-08-13 (currently waiting for approval).
I am also struggling to get around the search results provided by pytube Search module. Since search results are looking like objects, I was thinking (lazily) that I cannot convert the object list in to strings.
After modifying your function as below, the results are printed as youtube links.
'''
def videoSearch(search_list): #provide the search.results list as input
for result in search_list: #Begin video id extraction
result = str(result)
temp = result.replace("<pytube.__main__.YouTube object: videoId=", "")
temp = temp.split(',')[0] #get the correct video id
vidLink = ("https://www.youtube.com/watch?v=" + temp)
print(vidLink)
'''
Try it out.
I have this script that tries to find Style + Year on Discogs and writes it to the mp3 file.
It used to work before.
But now I get this error:
Index Error: list index out of range
I've de-installed 3.7.2, and re-installed 3.6.3 since I have chat logs where it shows it's working back then on that version.
When I set sys.argument to 0, no error, but no execution either.
for mp3file in Path(sys.argv[1]).glob('**/*.mp3'):
print (mp3file)
artist, title = return_tag_data(mp3file)
artist_c = clean(artist)
title_c = clean(title)
style = get_style(artist_c, title_c, artist, title)
year = get_year(artist_c, title_c, artist, title)
if style != None:
print ("Artist : {}\nTitle : {}\nStyle : {}\nYear : {}\n".format(artist, title, style, year))
write_tag_data(mp3file, style, year)
It should show this:
c:\users\useraccount\music\My Music Collection\2-Step & Garage\187 Lockdown - Gunman (God Remix).mp3
Artist : 187 Lockdown
Title : Gunman (God Remix)
Style : Drum n Bass, Speed Garage
Year : 1997
But instead it throws this:
E:\test-mp3>python styleyear-mp3.py "e:\test-mp3"
e:\test-mp3\187 Lockdown - Gunman (GOD remix).mp3
Traceback (most recent call last):
File "styleyear-mp3.py", line 111, in <module>
style = get_style(artist_c, title_c, artist, title)
File "styleyear-mp3.py", line 50, in get_style
new_artist = y('spanitemprop title="(.+?)"')[0].strip()
IndexError: list index out of range
I'm using bibtexparser to parse a bibtex file.
import bibtexparser
with open('MetaGJK12842.bib','r') as bibfile:
bibdata = bibtexparser.load(bibfile)
While parsing I get the error message:
Could not parse properly, starting at
#article{Frenn:EvidenceBasedNursing:1999,
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyparsing.py", line 3183, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected end of text (at char 5773750),
(line:47478, col:1)`
The line refers to the following bibtex entry:
#article{Frenn:EvidenceBasedNursing:1999,
author = {Frenn, M.},
title = {A Mediterranean type diet reduced all cause and cardiac mortality after a first myocardial infarction [commentary on de Lorgeril M, Salen P, Martin JL, et al. Mediterranean dietary pattern in a randomized trial: prolonged survival and possible reduced cancer rate. ARCH INTERN MED 1998;158:1181-7]},
journal = {Evidence Based Nursing},
uuid = {15A66A61-0343-475A-8700-F311B08BB2BC},
volume = {2},
number = {2},
pages = {48-48},
address = {College of Nursing, Marquette University, Milwaukee, WI},
year = {1999},
ISSN = {1367-6539},
url = {},
keywords = {Treatment Outcomes;Mediterranean Diet;Mortality;France;Neoplasms -- Prevention and Control;Phase One Excluded - No Assessment of Vegetable as DV;Female;Phase One - Reviewed by Hao;Myocardial Infarction -- Diet Therapy;Diet, Fat-Restricted;Phase One Excluded - No Fruit or Vegetable Study;Phase One Excluded - No Assessment of Fruit as DV;Male;Clinical Trials},
tags = {Phase One Excluded - No Assessment of Vegetable as DV;Phase One Excluded - No Fruit or Vegetable Study;Phase One - Reviewed by Hao;Phase One Excluded - No Assessment of Fruit as DV},
accession_num = {2000008864. Language: English. Entry Date: 20000201. Revision Date: 20130524. Publication Type: journal article},
remote_database_name = {rzh},
source_app = {EndNote},
EndNote_reference_number = {4413},
Secondary_title = {Evidence Based Nursing},
Citation_identifier = {Frenn 1999a},
remote_database_provider = {EBSCOhost},
publicationStatus = {Unknown},
abstract = {Question: text.},
notes = {(0) abstract; commentary. Journal Subset: Core Nursing; Europe; Nursing; Peer Reviewed; UK \& Ireland. No. of Refs: 1 ref. NLM UID: 9815947.}
}
What is wrong with this entry?
It seems that the issue has been addressed and resolved in the project repository (see Issue 147)
Until the next release, installing the library from the git repository can serve as a temporary fix.
pip install --upgrade git+https://github.com/sciunto-org/python-bibtexparser.git#master
I had this same error and found an entry near the line mentioned in the error that had a line like this
...
year = {1959},
month =
}
When I removed the null month item it parsed for me.
My code simply uses BeautifulSoup parser to fetch the top movies from IMDB
website.
The code is as follows:
from bs4 import BeautifulSoup
import requests
import sys
url = "http://www.imdb.com/chart"
response = requests.get(url)
soup = BeautifulSoup(response.text)
tr = soup.findChildren("tr")
tr = iter(tr)
next(tr)
for movie in tr:
title = movie.find('td',{'class':'titleColumn'}).find('a').contents[0]
year = movie.find('td',{'class':'titleColumn'}).find('span',{'class':'secondaryInfo'}).contents[0]
rating = movie.find('td',{'class':'ratingColumn imdbRating'}).find('strong').contents[0]
row = title + "-" + year + " " + " " + rating
print(row)
It gives following error:
Traceback (most recent call last):
File "imdb_scrap.py", line 12, in <module>
year = movie.find('td',{'class':'titleColumn'}).find('span',{'class':'secondaryInfo'}).contents[0]
AttributeError: 'NoneType' object has no attribute 'contents'
The given code did run for the first time with incomplete output and the error while it didn't run at all later.
Sample output:
Stalker-(1979) 8.1
Paper Moon-(1973) 8.1
The Maltese Falcon-(1941) 8.1
The Truman Show-(1998) 8.1
Hachi: A Dog's Tale-(2009) 8.1
Le notti di Cabiria-(1957) 8.1
The Princess Bride-(1987) 8.1
Kaze no tani no Naushika-(1984) 8.1
Munna Bhai M.B.B.S.-(2003) 8.1
Before Sunrise-(1995) 8.1
Harry Potter and the Deathly Hallows: Part 2-(2011) 8.0
The Grapes of Wrath-(1940) 8.0
Prisoners-(2013) 8.0
Rocky-(1976) 8.0
Star Wars: Episode VII - The Force Awakens-(2015) 8.0
Touch of Evil-(1958) 8.0
Sholay-(1975) 8.0
Catch Me If You Can-(2002) 8.0
Gandhi-(1982) 8.0
Any help or suggestion will be appreciated.
Looking at your code the error lies in
.find('span',{'class':'secondaryInfo'}).contents[0]
This might not be the only error but this is the first one looking at the error message that it gave you. Also I know the first half of variable year is correct because it is the same as variable title.
With this in mind it is probably because you assumed that the year is located at [0] but this is obviously wrong because it tells you that location [0] has no info at all so if you were to print it as
print(movie.find('td',{'class':'titleColumn'}).find('span',{'class':'secondaryInfo'}).contents[0])
I would guarantee you will get None as the answer and that is NoneType which has no attributes.
search_response = youtube.search().list(q=options.q, type='video',
part='id,snippet', maxResults=options.max_results).execute()
videos = {}
# Add each result to the appropriate list, and then display the lists of
# matching videos.
# Filter out channels, and playlists.
for search_result in search_response.get('items', []):
if search_result['id']['kind'] == 'youtube#video':
# videos.append("%s" % (search_result["id"]["videoId"]))
videos[search_result['id']['videoId']] = search_result['snippet'
]['title']
# print "Videos:\n", "\n".join(videos), "\n"
s = ','.join(videos.keys())
videos_list_response = youtube.videos().list(id=s,
part='id,statistics,snippet').execute()
res = []
for i in videos_list_response['items']:
tempres = dict(v_id=i['id'], v_title=videos[i['id']])
tempres.update(i['snippet'])
tempres.update(i['statistics'])
res.append(tempres)
Please enter the search term for videos: football
Your search term is: football
Traceback (most recent call last):
File "data_pull.py", line 61, in
tempres.update(i['statistics'])
KeyError: 'statistics'
Need help to solve this error. got this code from https://www.analyticsvidhya.com/blog/2014/09/mining-youtube-python-social-media-analysis/#comment-126365 and not able to solve this error.
this file ran before error free, but after 4-5 days this error has popped up without changing the code.
Its weird but help would be appreciated!
Thanks
Because with some videos, you cannot get its statistics.
Try with Search term = Lac Troi Son Tung MTP and you will find out this video does not have statistics attribute.