Pytube module title not giving - python

I am trying to get Youtube video title using pytube module
But it giving error . I have tried this code :
import pytube
from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=Srqs4CitU2U')
print(video.title)
But it Giving Me This Error :
PS D:\Programming> & "C:/Users/Offensive Tech/AppData/Local/Programs/Python/Python39/python.exe" d:/Programming/youtube_video.py
Traceback (most recent call last):
File "d:\Programming\youtube_video.py", line 4, in <module>
video = YouTube('https://www.youtube.com/watch?v=Srqs4CitU2U')
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 91, in __init__
self.prefetch()
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 181, in prefetch
self.vid_info_raw = request.get(self.vid_info_url)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\request.py", line 36, in get
return _execute_request(url).read().decode("utf-8")
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\request.py", line 24, in _execute_request
return urlopen(request) # nosec
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 555, in error
result = self._call_chain(*args)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 747, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
return self._call_chain(*args)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "C:\Users\Offensive Tech\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 641, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 410: Gone
PS D:\Programming>
Please tell me the solution that error can solved.

You get 410 Error, it's said the page remove from the web. i think is happened because who publish the video remove it from YouTube. I check the code now, and it is work.

Related

Receiving error downloading with urllib via url

Using the code below, this should have downloaded ~14,000 images. I know the call works for the cards because I ran this without the image download.
A blob file showed up in my downloads, but then was deleted. No files to be found.
Where is the potential error? When this is successful - where would they potentially download to?
Traceback (most recent call last):
File "c:\Users\toril\OneDrive\Documents\Pokemon AI\image download.py", line 28, in <module>
urllib.request.urlretrieve("https://images.pokemontcg.io/sm75/1_hires.png", "sm75-1.jpg")
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 241, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 525, in open
response = meth(req, response)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 634, in http_response
response = self.parent.error(
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 563, in error
return self._call_chain(*args)
fields = ['card', 'c_image']
Cards = Card.all()
with open ('pokemontest3.csv', 'w', newline='', encoding='utf-8') as csv_file:
csvwriter = csv.writer(csv_file)
csvwriter.writerow(fields)
for card in Cards:
card = (card.name, card.images.small)
rows = card
csvwriter.writerow(rows)
urllib.request.urlretrieve("https://images.pokemontcg.io/sm75/1_hires.png", "sm75-1.jpg")
Why all the CSV-code, if it's a problem with image-fetching?
Why downloading the same image is within a loop?
It looks like your traceback is truncated, and it's a simple "403 Forbidden" error:
>> urllib.request.urlretrieve("https://images.pokemontcg.io/sm75/1_hires.png", "/tmp/sm75-1.jpg")
Traceback (most recent call last):
File "<input>", line 1, in <module>
urllib.request.urlretrieve("https://images.pokemontcg.io/sm75/1_hires.png", "/tmp/sm75-1.jpg")
File "/usr/local/Cellar/python#3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request
.py", line 241, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/usr/local/Cellar/python#3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request
.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/Cellar/python#3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request
.py", line 525, in open
response = meth(req, response)
File "/usr/local/Cellar/python#3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request
.py", line 634, in http_response
response = self.parent.error(
File "/usr/local/Cellar/python#3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request
.py", line 563, in error
return self._call_chain(*args)
File "/usr/local/Cellar/python#3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request
.py", line 496, in _call_chain
result = func(*args)
File "/usr/local/Cellar/python#3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request
.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

Getting error code when trying to download using pytube

Not sure what it is, but its been driving me nuts and im such a newbie I tried so many things but im not sure what it means, ive tried installing and reinstalling pytube but nothing changed.
Here's my code
from pytube import YouTube
link = input("Enter in a link: ")
video = YouTube(link)
print(video.title)
print(video.streams.filter(progressive=True))
stream = video.streams.get_by_itag(22)
stream.download()
print("Video downloaded")
The entire error message:
Traceback (most recent call last):
- File "c:\PytubeDownloader\YoutubeDownloader2.py", line 5, in <module>
video = YouTube(link)
- File "C:\Python\lib\site-packages\pytube\__main__.py", line 91, in __init__
self.prefetch()
- File "C:\Python\lib\site-packages\pytube\__main__.py", line 181, in prefetch
self.vid_info_raw = request.get(self.vid_info_url)
- File "C:\Python\lib\site-packages\pytube\request.py", line 36, in get
return _execute_request(url).read().decode("utf-8")
- File "C:\Python\lib\site-packages\pytube\request.py", line 24, in _execute_request
return urlopen(request) # nosec
- File "C:\Python\lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
- File "C:\Python\lib\urllib\request.py", line 525, in open
response = meth(req, response)
- File "C:\Python\lib\urllib\request.py", line 634, in http_response
response = self.parent.error(
- File "C:\Python\lib\urllib\request.py", line 557, in error
result = self._call_chain(*args)
- File "C:\Python\lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
- File "C:\Python\lib\urllib\request.py", line 749, in http_error_302
return self.parent.open(new, timeout=req.timeout)
- File "C:\Python\lib\urllib\request.py", line 525, in open
response = meth(req, response)
- File "C:\Python\lib\urllib\request.py", line 634, in http_response
response = self.parent.error(
- File "C:\Python\lib\urllib\request.py", line 563, in error
return self._call_chain(*args)
- File "C:\Python\lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
- File "C:\Python\lib\urllib\request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 410: Gone
Ok so I did what was recommended in Pytube: urllib.error.HTTPError: HTTP Error 410: Gone and now im getting a completely different error
Traceback (most recent call last):
File "c:\PytubeDownloader\YoutubeDownloader2.py", line 9, in
print(video.streams.filter(progressive=True))
File "C:\Python\lib\site-packages\pytube_main_.py", line 292, in streams
return StreamQuery(self.fmt_streams)
File "C:\Python\lib\site-packages\pytube_main_.py", line 184, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Python\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Python\lib\site-packages\pytube\cipher.py", line 33, in init
raise RegexMatchError(
pytube.exceptions.RegexMatchError: init: could not find match for ^\w+\W
Experienced same error. In cipher.py replace the regexs in pattern in get_initial_function_name with:
r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('.

urllib.error.HTTPError: HTTP Error 404: Not Found yfinance library

I keep getting this error while using:
import yfinance as yf
msft = yf.Ticker("MSFT")
msft.info
Traceback (most recent call last):
Python Shell, prompt 15, line 6
File "C:\Users\i\miniconda3\Lib\site-packages\yfinance\ticker.py", line 138, in info
return self.get_info()
File "C:\Users\i\miniconda3\Lib\site-packages\yfinance\base.py", line 415, in get_info
self._get_fundamentals(proxy)
File "C:\Users\i\miniconda3\Lib\site-packages\yfinance\base.py", line 284, in _get_fundamentals
holders = _pd.read_html(url)
File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 1100, in read_html
displayed_only=displayed_only,
File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 895, in _parse
tables = p.parse_tables()
File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 213, in parse_tables
tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 733, in _build_doc
raise e
File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 714, in _build_doc
with urlopen(self.io) as f:
File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\common.py", line 141, in urlopen
return urllib.request.urlopen(*args, **kwargs)
File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
I have tried updating packages and uninstalling and reinstalling the library but nothing is seems to work.
According to this ticker, it's a bug in yfinance library.
So let me read the comments:
One person fixed that with monkey-patching the library changing lines of base.py:
holders = _pd.read_html(url)
with:
r = _requests.get(url,headers={'User-Agent': 'Mozilla/5.0'})
holders = _pd.read_html(r.content)
Another person installed the package from different source:
pip install -i https://pypi.anaconda.org/ranaroussi/simple yfinance
Tested last one, it works. Good luck.

Pytube HTTPError: HTTP Error 429: Too Many Requests

I was going to download youtube video so wrote a code in python using pytube module.
I tried pip install pytube and pip install pytube3 .
Only pytube3 worked for me .
from pytube import YouTube
url = 'https://www.youtube.com/watch?v=lJ08IGp5ulA&t=23s'
yt = YouTube(url)
videos = yt.streams.all()
print(videos)
I used this code but got error like
Traceback (most recent call last):
File "c:\Users\ASUS\Desktop\utube\sunil.py", line 5, in <module>
yt = YouTube(url)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytube\__main__.py", line 91, in __init__
self.prefetch()
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytube\__main__.py", line 162, in prefetch
self.watch_html = request.get(url=self.watch_url)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytube\request.py", line 36, in get
return _execute_request(url).read().decode("utf-8")
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytube\request.py", line 24, in _execute_request
return urlopen(request) # nosec
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 640, in http_response
response = self.parent.error(
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 563, in error
result = self._call_chain(*args)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 755, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 640, in http_response
response = self.parent.error(
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 429: Too Many Requests
So help me to fix this.

yahoo_finance api throws 404. urllib2.HTTPError: HTTP Error 400: Bad Request

$ pip install yahoo-finance
$ python
Then in python console,
>>> from yahoo_finance import Share
>>> yahoo = Share('YHOO')
Traceback (most recent call last): File "", line 1, in File
"/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/init.py",
line 178, in init
self.refresh() File "/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/init.py",
line 142, in refresh
self.data_set = self._fetch() File "/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/init.py",
line 181, in _fetch
data = super(Share, self)._fetch() File "/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/init.py",
line 134, in _fetch
data = self._request(query) File "/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/init.py",
line 118, in _request
response = yql.YQLQuery().execute(query) File "/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/yql.py",
line 61, in execute
'env': DATATABLES_URL File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout) File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 435, in open
response = meth(req, response) File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs) File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 473, in error
return self._call_chain(*args) File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args) File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 400: Bad Request

Categories