"KeyError: title" with PyTube - python

I have the following code:
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=9bZkp7q19f0')
print(yt.title)
And am being thrown the following error
Traceback (most recent call last):
File "C:\Users\tom\Desktop\Desktop\archiver.py", line 4, in <module>
print(yt.title)
File "C:\Users\tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytube\__main__.py", line 254, in title
return self.player_config_args['title']
KeyError: 'title'
What is going wrong here?

A lot of people having this issue, one suggested thing to try is to make the following changes mentioned in this pull request.
https://github.com/nficano/pytube/pull/435/files.

Related

Error when trying to open a webpage with mechanize

I'm trying to learn mechanize to create a chat logging bot later, so I tested out some basic code
import mechanize as mek
import re
br = mek.Browser()
br.open("google.com")
However, whenever I run it, I get this error.
Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/mechanize/_mechanize.py", line 262, in _mech_open
url.get_full_url
AttributeError: 'str' object has no attribute 'get_full_url'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 5, in <module>
br.open("google.com")
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/mechanize/_mechanize.py", line 253, in open
return self._mech_open(url_or_request, data, timeout=timeout)
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/mechanize/_mechanize.py", line 269, in _mech_open
raise BrowserStateError("can't fetch relative reference: "
mechanize._mechanize.BrowserStateError: can't fetch relative reference: not viewing any document
I double checked with the documentation on the mechanize page and it seems consistent. What am I doing wrong?
You have to use a schema, otherwise mechanize thinks you are trying to open a local/relative path (as the error suggests).
br.open("google.com") should be br.open("http://google.com").
Then you will see an error mechanize._response.httperror_seek_wrapper: HTTP Error 403: b'request disallowed by robots.txt', because google.com does not allow crawlers. This can be remedied with br.set_handle_robots(False) before open.

pytube-Youtube function not initializing

I have pytube installed, i am getting an error when i run it(I am using python 3.7), the problem seems to be with the pytube itself ,i am using exact code of tutorials for this module.
import pytube
link ='https://www.youtube.com/watch?v=9bZkp7q19f0'
yt = pytube.YouTube(link)
stream = yt.streams.first()
finished = stream.download()
print('Download is complete')
Traceback (most recent call last):
File "C:\automate the boring stuff\youtubetry.py", line 6, in <module>
yt = pytube.YouTube(link)
File "C:\Users\diodi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytube\__main__.py", line 88, in __init__
self.prefetch_init()
[Finished in 6.0s with exit code 1]
I had this issue last week. Since I'm on Ubuntu, what worked for me was navigating to:
/home/<username>/anaconda3/lib/python3.6/site-packages/pytube
and adding
r'\bc\s*&&\s*d\.set\([^,]+,.*?\((?P<sig>[a-zA-Z0-9$]+)\(\(0\s*,\s*window.decodeURIComponent'
to the list of patterns in the get_initial_function_name() function in cipher.py. The error was further discussed in this Github thread.

Pyshark FileCapture doesn't work

I'm new with pyshark, and I write a sample code by searching on the tutorial
import pyshark
cap = pyshark.FileCapture("input.cap")
cap_1 = cap[0]
and then it give me an error
/Users/tingyugu/anaconda3/bin/python /Users/tingyugu/PycharmProjects/final/test.py
Traceback (most recent call last):
File "/Users/tingyugu/anaconda3/lib/python3.6/site-packages/pyshark/capture/file_capture.py", line 70, in __getitem__
next(self)
File "/Users/tingyugu/anaconda3/lib/python3.6/site-packages/pyshark/capture/file_capture.py", line 60, in __next__
packet = self._packet_generator.send(None)
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/tingyugu/PycharmProjects/final/test.py", line 5, in <module>
cap_1 = cap[0]
File "/Users/tingyugu/anaconda3/lib/python3.6/site-packages/pyshark/capture/file_capture.py", line 73, in __getitem__
raise KeyError('Packet of index %d does not exist in capture' % packet_index)
KeyError: 'Packet of index 0 does not exist in capture'
I know the reason is that there is no packets in the cap, but my friend can read the file by pyshark
I use the python 3.6.0 anaconda and the pyshark is 0.3.7 in anaconda
if you are on jupyter see this issue on PyShark Repo. I had the same problem, seems like pyshark does not go well with jupyter. I'm gonna assume it might have same issues with ipython as well.
there are some pull requests like this one on their repo too as a fix but nothing merged yet.

jirashell throws a "KeyError: u'consumer_key'" and does not start

I am new to jira-python and have run into an issue with using jirashell.
jira-python was installed from documentation given here: http://jira.readthedocs.org/en/latest/
When I try to start jirashell using:
ubuntu#ip-10-0-0-12:~$ jirashell -s https://jira.atlassian.com
I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/jirashell", line 11, in <module> sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/jira/jirashell.py", line 248, in main
jira = JIRA(options=options, basic_auth=basic_auth, oauth=oauth)
File "/usr/local/lib/python2.7/dist-packages/jira/client.py", line 202, in __init__self._create_oauth_session(oauth)
File "/usr/local/lib/python2.7/dist-packages/jira/client.py", line 1871, in _create_oauth_session
oauth['consumer_key'],
KeyError: u'consumer_key'
I have also tried to get to a server using basic auth but that returns the same error. Using curl works fine, but I wanted to see the objects that are getting returned and get help as I develop by python-jira integration.
Thank you for any insight.

How to get active tab url from browser?

How do I get URL from current tab in browser using python? Using os.environ['REQUEST_URI'] gives an error.
The following is my code :
os.environ['REQUEST_URI']
and the error :
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
os.environ["REQUEST_URI"]
File "C:\Python27\lib\os.py", line 423, in __getitem__
return self.data[key.upper()]
KeyError: 'REQUEST_URI'
Any other alternatives are also welcome.
Alternate to your asked way by "os.environ", you can do it:
by copy and past by hand
on other ways than you asked way by python
by Brotab
by Selenium
by xdotool
by javascript from serversite or by code injection from client side

Categories

Resources