I am trying to make a python program which downloads youtube video when link given using Pytube module but when i try to run it, its giving a huge error which is as follows-
Traceback (most recent call last):
File "c:\Users\Sumit\vs code python\projects\proj's\yt.py", line 9, in <module>
yt = YouTube(link)
File "C:\Python39\lib\site-packages\pytube\__main__.py", line 91, in __init__
self.prefetch()
File "C:\Python39\lib\site-packages\pytube\__main__.py", line 181, in prefetch
self.vid_info_raw = request.get(self.vid_info_url)
File "C:\Python39\lib\site-packages\pytube\request.py", line 36, in get
return _execute_request(url).read().decode("utf-8")
File "C:\Python39\lib\site-packages\pytube\request.py", line 24, in _execute_request
return urlopen(request) # nosec
File "C:\Python39\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "C:\Python39\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "C:\Python39\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "C:\Python39\lib\urllib\request.py", line 555, in error
result = self._call_chain(*args)
File "C:\Python39\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "C:\Python39\lib\urllib\request.py", line 747, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Python39\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "C:\Python39\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "C:\Python39\lib\urllib\request.py", line 561, in error
return self._call_chain(*args)
File "C:\Python39\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "C:\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
I dont know whats the problem and I am not understanding what should I do, Please help.
Also, I am using python 3.9,the code is given below-
from pytube import YouTube
SAVE_PATH = r"C:\Users\Sumit\vs code python\projects"
link="https://www.youtube.com/watch?v=JfVOs4VSpmA&t=3s"
yt = YouTube(link)
mp4files = yt.filter('mp4')
yt.set_filename('Video')
Avideo = yt.get(mp4files[-1].extension,mp4files[-1].resolution)
try:
# downloading the video
Avideo.download(SAVE_PATH)
except:
print("Some Error!")
print('Task Completed!')
https://pytube.io/en/latest/api.html#pytube.Stream.download
from pytube import YouTube
SAVE_PATH = r"C:\Users\Sumit\vs code python\projects"
link="https://www.youtube.com/watch?v=JfVOs4VSpmA&t=3s"
yt = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')
yt.streams
.filter(progressive=True, file_extension='mp4')
.order_by('resolution')
.desc()
.first()
.download(SAVE_PATH, 'videoFilename', 'mp4')
Related
I'm trying to export data from Google Search Console to Big Query using Python. However it keeps timing out and I keep getting the following error:
Traceback (most recent call last):
File "/Users/markleach/Python/GSC_BQ/gsc_bq.py", line 147, in <module>
y = get_sc_df(p,"2021-12-01","2022-12-01",x)
File "/Users/markleach/Python/GSC_BQ/gsc_bq.py", line 71, in get_sc_df
response = service.searchanalytics().query(siteUrl=site_url, body=request).execute()
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/googleapiclient/http.py", line 923, in execute
resp, content = _retry_request(
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/googleapiclient/http.py", line 222, in _retry_request
raise exception
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/googleapiclient/http.py", line 191, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/google_auth_httplib2.py", line 218, in request
response, content = self.http.request(
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/httplib2/__init__.py", line 1720, in request
(response, content) = self._request(
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/httplib2/__init__.py", line 1440, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/site-packages/httplib2/__init__.py", line 1392, in _conn_request
response = conn.getresponse()
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/http/client.py", line 1377, in getresponse
response.begin()
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/http/client.py", line 320, in begin
version, status, reason = self._read_status()
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/http/client.py", line 281, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/ssl.py", line 1242, in recv_into
return self.read(nbytes, buffer)
File "/Users/markleach/opt/anaconda3/envs/Sandpit/lib/python3.9/ssl.py", line 1100, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
This is the code around the mentioned lines:
for p in PROPERTIES:
for x in range(0,100000,25000):
y = get_sc_df(p,"2021-12-01","2022-12-01",x)
if len(y) < 25000:
break
else:
continue
I'd be grateful for any advice on how to correct this. Thanks in advance.
Mark
ps whole code in picture format below as i'm not allowed to have more code than text
Script was timing out because of the size of the dataset required.
Since a week I'm facing a weird bug on my python server.
Right now it is running on Requests version 2.23.0 without issue.
Because of vulnerability issue I'd like to bump the Requests version to the 2.26.0.
My servers runs ok until I try to run a piece of code like that:
import requests
from firebase_admin import auth
bearer_token = requests.headers['X-Bearer-Token'] # Usually there is the word `Bearer`, consider we remove it.
decoded_token = auth.verify_id_token(bearer_token, check_revoked=False)
This piece of code will raise:
RecursionError: maximum recursion depth exceeded
Full error:
Traceback (most recent call last):
File "./project/handlers/users.py", line 106, in get_user
decoded_token = auth.verify_id_token(a, check_revoked=False)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/auth.py", line 220, in verify_id_token
return client.verify_id_token(id_token, check_revoked=check_revoked)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_auth_client.py", line 127, in verify_id_token
verified_claims = self._token_verifier.verify_id_token(id_token)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_token_gen.py", line 293, in verify_id_token
return self.id_token_verifier.verify(id_token, self.request)
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_token_gen.py", line 396, in verify
certs_url=self.cert_url)
File "./project/venv/lib/python3.6/site-packages/google/oauth2/id_token.py", line 124, in verify_token
certs = _fetch_certs(request, certs_url)
File "./project/venv/lib/python3.6/site-packages/google/oauth2/id_token.py", line 98, in _fetch_certs
response = request(certs_url, method="GET")
File "./project/venv/lib/python3.6/site-packages/firebase_admin/_token_gen.py", line 266, in __call__
url, method=method, body=body, headers=headers, timeout=timeout, **kwargs)
File "./project/venv/lib/python3.6/site-packages/google/auth/transport/requests.py", line 184, in __call__
method, url, data=body, headers=headers, timeout=timeout, **kwargs
File "./project/venv/lib/python3.6/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "./project/venv/lib/python3.6/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "./project/venv/lib/python3.6/site-packages/cachecontrol/adapter.py", line 57, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "./project/venv/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "./project/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "./project/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "./project/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
conn.connect()
File "./project/venv/lib/python3.6/site-packages/urllib3/connection.py", line 332, in connect
cert_reqs=resolve_cert_reqs(self.cert_reqs),
File "./project/venv/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 281, in create_urllib3_context
context.options |= options
File "/usr/local/lib/python3.6/ssl.py", line 465, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 465, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 465, in options
super(SSLContext, SSLContext).options.__set__(self, value)
[Previous line repeated 963 more times]
File "/usr/local/lib/python3.6/ssl.py", line 463, in options
#options.setter
RecursionError: maximum recursion depth exceeded
Librairies:
requests = ^2.24.0
firebase-admin = ^5.0.0
I solved it by removing the Eventlet Monkey patch.
eventlet.monkey_patch()
I was following a tutorial and when using request.urlopen(url) I get an error, I have tried checking the URL
(https://www.wsj.com/market-data/quotes/PH/XPHS/JFC/historical-prices/download?MOD_VIEW=page&num_rows=150&range_days=150&startDate=06/01/2020&endDate=07/05/2020)
and it's fine.
Here is my code:
from urllib import request
import datetime
def download_stock_from_day_until_today(stock_code, start_date):
current_day = datetime.date.today()
formatted_current_day = datetime.date.strftime(current_day, "%m/%d/%Y") #formats today's date for links
#formatted url
url = "https://www.wsj.com/market-data/quotes/PH/XPHS/"+ stock_code +"/historical-prices/download?MOD_VIEW=page&num_rows=150&range_days=150&startDate="+ start_date +"&endDate=" + formatted_current_day
print(url)
response = request.urlopen(url) #requests the csv file
csv = response.read() #reads the csv file
csv_str = str(csv)
lines = csv_str.split("\\n")
dest_url = r'asd.csv'
fx = open(dest_url, "w")
for line in lines:
fx.write(line + "\n")
fx.close()
download_stock_from_day_until_today("JFC", "06/01/2020")
and the error I get in the console is:
Traceback (most recent call last):
File "C:/Users/Lathrix/PycharmProject/StockExcelDownloader/main.py", line 23, in <module>
download_stock_from_day_until_today("JFC", "06/01/2020")
File "C:/Users/Lathrix/PycharmProject/StockExcelDownloader/main.py", line 12, in download_stock_from_day_until_today
response = request.urlopen(url) #requests the csv file
File "C:\Users\Lathrix\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Lathrix\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\Lathrix\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 640, in http_response
response = self.parent.error(
File "C:\Users\Lathrix\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\Lathrix\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\Lathrix\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 404: Not Found
Looks like wsj.com does not like urllib's User-Agent.
With the line
response = request.urlopen(request.Request(url,headers={'User-Agent': 'Mozilla/5.0'}))
your code works correctly
In such this situation:
there is a list on the page
below it have one check for check all of the list item,and a div to receive all of the list,
after click it will pop up a alert,after click accept the page will close.
onclick=checkedalldoc();#check
onclick=responseclick();#div
I need use selenium with IE to automatically these
this is my basepage.py for packaging code:
# 点击元素
def click(self, *selector):
el = self.find_element(*selector)
try:
el.click()
logger.info('元素'%s' 已被点击.' % el.text)
except NameError as e:
logger.error('Failed to click the element with %s' % e)
#运行js脚本
def run_script(self, js):
try:
self.driver.execute_script(js)
logger.info('成功运行脚本,脚本内容为:%s.' % js)
except BaseException:
logger.error('js脚本运行错误.')
#切换至弹窗并点击确定
def accept_alert(self):
try:
WebDriverWait(self.driver, 20).until(EC.alert_is_present())
alert = self.driver.switch_to.alert
alert.accept()
logger.info('获得弹出框并选择确认.')
except BaseException:
logger.error('弹出框失败.')
this is logic function
def receive_all_docs(self):
self.click(*self.chkall_checkbox)
self.click(*self.response_btn)
self.accept_alert()
When it works, it prompts the following error and it does not complete the function:
Traceback (most recent call last):
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 416, in _make_request
httplib_response = conn.getresponse()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 1322, in getresponse
response.begin()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 303, in begin
version, status, reason = self._read_status()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 264, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "c:\users\a\appdata\local\programs\python\python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "e:\Dropbox\17.Develop\5.Project\autozboa\run.py", line 22, in <module>
manage()
File "e:\Dropbox\17.Develop\5.Project\autozboa\run.py", line 14, in manage
m.handle_doc() # 处理单个文件
File "e:\Dropbox\17.Develop\5.Project\autozboa\manage.py", line 67, in handle_doc
docs_unid = docs.get_docs_unid()
File "e:\Dropbox\17.Develop\5.Project\autozboa\zboa\pages\docs_page.py", line 38, in get_docs_unid
for doc in self.find_elements(*self.docs_link):
File "e:\Dropbox\17.Develop\5.Project\autozboa\zboa\framework\base_page.py", line 70, in find_elements
elements = self.driver.find_elements(*selector)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1005, in find_elements
return self.execute(Command.FIND_ELEMENTS, {
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 402, in _request
resp = http.request(method, url, body=body, headers=headers)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\request.py", line 79, in request
return self.request_encode_body(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\request.py", line 171, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\poolmanager.py", line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\util\retry.py", line 400, in increment
raise six.reraise(type(error), error, _stacktrace)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\urllib3\connectionpool.py", line 416, in _make_request
httplib_response = conn.getresponse()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 1322, in getresponse
response.begin()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 303, in begin
version, status, reason = self._read_status()
File "c:\users\a\appdata\local\programs\python\python38\lib\http\client.py", line 264, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "c:\users\a\appdata\local\programs\python\python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None))
i would try two things here
first, syntax:
as described in selenium-python docs, accepting alert is done by:
from selenium.webdriver.common.alert import Alert
Alert(driver).accept()
second, you should check exectly which row produces the exception.
UnexpectedAlertPresentException occurs when you are trying to preform an action while an alert is open. is it possible that those "click" actions are called when an alert is already open?
I am trying to retrieve an object from S3 using boto3 as follows:
s3 = boto3.resource('s3')
streaming_body = s3.Object(bucket_name=s3bucket,
key=documentPath
)
body = {}
body['filename'] = documentName
body['file'] = streaming_body.get()['Body'].read()
This works fine on my local machine in PyCharm. However, when I upload to Lambda and make an API call, the following error is returned:
Traceback (most recent call last):
'File "/var/task/s3getdocument.py", line 73, in lambda_handler
body['file'] = streaming_body.get()['Body'].read()
File "/opt/python/lib/python3.7/site-packages/boto3/resources/factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "/opt/python/lib/python3.7/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/opt/python/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/python/lib/python3.7/site-packages/botocore/client.py", line 648, in _make_api_call
operation_model, request_dict, request_context)
File "/opt/python/lib/python3.7/site-packages/botocore/client.py", line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/opt/python/lib/python3.7/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/opt/python/lib/python3.7/site-packages/botocore/endpoint.py", line 135, in _send_request
request, operation_model, context)
File "/opt/python/lib/python3.7/site-packages/botocore/endpoint.py", line 167, in _get_response
request, operation_model)
File "/opt/python/lib/python3.7/site-packages/botocore/endpoint.py", line 218, in _do_get_response
response_dict, operation_model.output_shape)
File "/opt/python/lib/python3.7/site-packages/botocore/parsers.py", line 242, in parse
parsed = self._do_parse(response, shape)
File "/opt/python/lib/python3.7/site-packages/botocore/parsers.py", line 774, in _do_parse
member_shapes, final_parsed)
File "/opt/python/lib/python3.7/site-packages/botocore/parsers.py", line 833, in _parse_non_payload_attrs
member_shape, headers[header_name])
File "/opt/python/lib/python3.7/site-packages/botocore/parsers.py", line 302, in _parse_shape
return handler(shape, node)
File "/opt/python/lib/python3.7/site-packages/botocore/parsers.py", line 175, in _get_text_content
return func(self, shape, text)
File "/opt/python/lib/python3.7/site-packages/botocore/parsers.py", line 462, in _handle_timestamp
return self._timestamp_parser(text)
File "/opt/python/lib/python3.7/site-packages/botocore/utils.py", line 567, in parse_timestamp
return dateutil.parser.parse(value, tzinfos={'GMT': tzutc()})
File "/opt/python/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 1358, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/opt/python/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 657, in parse
ret = self._build_tzaware(ret, res, tzinfos)
File "/opt/python/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 1175, in _build_tzaware
aware = self._assign_tzname(aware, res.tzname)
File "/opt/python/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 1238, in _assign_tzname
new_dt = tz.enfold(dt, fold=1)
AttributeError: module 'dateutil.tz' has no attribute 'enfold
All modules are the same versions in the lambda as they are on my local machine. I am using the latest version of boto3 and botocore as of today (5/30).
Any advise on what the difference might be that would cause this?
This worked perfectly fine for me (on a small file):
import boto3
s3bucket = 'my-bucket'
documentPath='foo.txt'
def lambda_handler(event, context):
s3 = boto3.resource('s3')
streaming_body = s3.Object(bucket_name=s3bucket,
key=documentPath
)
body = {}
body['filename'] = documentPath # Changed this
body['file'] = streaming_body.get()['Body'].read()
print(body['file'])