Suds-jurko http error - python-3.x

I use python3 and sud-jurko
This my code:
from suds.client import Client
from suds.transport.http import HttpAuthenticated
wsdl_url = 'http://192.168.1.5/Base/ws/ws1.1cws'
t = HttpAuthenticated(username='login', password='pass')
client = Client(url=wsdl_url, transport=t)
print (client)
When run i get error:
(testik) C:\Users\Admin\testik>python test.py
Traceback (most recent call last):
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 67
, in open
return self.u2open(u2request)
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 13
2, in u2open
return url.open(u2request, timeout=tm)
File "C:\Python34\lib\urllib\request.py", line 469, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 579, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 507, in error
return self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py", line 441, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 587, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Authorization Required
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 16, in <module>
client = Client(url=wsdl_url, transport=t)
File "C:\Users\Admin\testik\lib\site-packages\suds\client.py", line 115, in __
init__
self.wsdl = reader.open(url)
File "C:\Users\Admin\testik\lib\site-packages\suds\reader.py", line 150, in op
en
d = self.fn(url, self.options)
File "C:\Users\Admin\testik\lib\site-packages\suds\wsdl.py", line 136, in __in
it__
d = reader.open(url)
File "C:\Users\Admin\testik\lib\site-packages\suds\reader.py", line 74, in ope
n
d = self.download(url)
File "C:\Users\Admin\testik\lib\site-packages\suds\reader.py", line 92, in dow
nload
fp = self.options.transport.open(Request(url))
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 23
5, in open
return HttpTransport.open(self, request)
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 69
, in open
raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 401: Authorization Required
(testik) C:\Users\Admin\testik>
What i am doing wrong. Please help me.
.-----------------------
. ------------------
.------------------
.---------------------
.------------------

Related

Can't download video using pytube

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')

SSL certificate expired error for influxdb-client

I have a windows 10 machine, and I am not sure what the problem is, I was able to run everything until a few hours back and now I keep running into SSL certificate Expired error for some reason.
Steps to reproduce:
This is my code.
'''
'''
from datetime import datetime
from influxdb_client import InfluxDBClient
config = {
'start': datetime.date(datetime(2021, 4, 7)),
'stop': datetime.date(datetime(2021, 4, 10)),
'bucket': "hidden",
'org': "hidden",
'url': "hidden",
'token': "hidden",
'measurement-name': "hidden",
}
client = InfluxDBClient(
url="https://eu-central-1-1.aws.cloud2.influxdata.com",
org=config['org'],
bucket=config['bucket'],
token=config['token'],
# verify_ssl=False
)
query_api = client.query_api()
ticker = 'TSLA'
results_df = query_api.query_data_frame(
f'from(bucket:"{config["bucket"]}")'
f'|> range(start: {config["start"]}, stop: {config["stop"]}) '
'|> filter(fn: (r) =>'
f' r._measurement == "{config["measurement-name"]}"'
f' and r.symbol == "{ticker}"'
') '
'|> filter (fn: (r) =>'
' r._field == "price"'
') '
'|> pivot('
' rowKey:["_time"],'
' columnKey: ["_field"],'
' valueColumn: "_value"'
') '
'|> sort(columns: ["_time"], desc: false) '
)
print(results_df)
Expected behavior:
I expect it to give me a dataframe like it always does and as you can see when I keep the ssl_verify=False it works.
result table _time _start _stop _measurement source symbol price
0 _result 0 2021-04-07 00:00:00+00:00 2021-04-07 00:00:00+00:00 2021-04-08 00:00:00+00:00 public_instruments_data YAHOO-FINANCE TSLA 670.969971
Actual behavior:
Traceback (most recent call last):
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "d:\MAIN_ENV\lib\site-packages\urllib3\connection.py", line 411, in connect
self.sock = ssl_wrap_socket(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\rest.py", line 181, in request
r = self.pool_manager.request(
File "d:\MAIN_ENV\lib\site-packages\urllib3\request.py", line 78, in request
return self.request_encode_body(
File "d:\MAIN_ENV\lib\site-packages\urllib3\request.py", line 170, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "d:\MAIN_ENV\lib\site-packages\urllib3\poolmanager.py", line 375, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\retry.py", line 507, in increment
raise six.reraise(type(error), error, _stacktrace)
File "d:\MAIN_ENV\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "d:\MAIN_ENV\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "d:\MAIN_ENV\lib\site-packages\urllib3\connection.py", line 411, in connect
self.sock = ssl_wrap_socket(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "d:\MAIN_ENV\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\khans\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\backend-dev-plaid\test_app_5.py", line 26, in <module>
results_df = query_api.query_data_frame(
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\client\query_api.py", line 146, in query_data_frame
_generator = self.query_data_frame_stream(query, org=org, data_frame_index=data_frame_index, params=params)
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\client\query_api.py", line 172, in query_data_frame_stream
response = self._query_api.post_query(org=org, query=self._create_query(query, self.default_dialect, params),
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\service\query_service.py", line 260, in post_query
(data) = self.post_query_with_http_info(**kwargs) # noqa: E501
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\service\query_service.py", line 340, in post_query_with_http_info
return self.api_client.call_api(
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\api_client.py", line 341, in call_api
return self.__call_api(resource_path, method,
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\api_client.py", line 171, in __call_api
response_data = self.request(
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\api_client.py", line 386, in request
return self.rest_client.POST(url,
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\rest.py", line 302, in POST
return self.request("POST", url,
File "d:\MAIN_ENV\lib\site-packages\influxdb_client\rest.py", line 238, in request
raise ApiException(status=0, reason=msg)
influxdb_client.rest.ApiException: (0)
Reason: SSLError
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)
Specifications:
Client Version: 1.21.0
InfluxDB Version: 2.0
Platform: Windows 10 home
Python: 3.9.7
I tried reinstalling python and all the libraries again just make sure the problem wasn't at my end and I also followed the urllib3 docs for installing the certificates from certifi and urllib3[secure] as suggested when I keep ssl_verify=False.
Any help would be much appreciated, thanks a lot in advance.
Just use ..., ssl_ca_cert=certifi.where(), ... as a temporary solution, but anyways since posting the question it seems the certificates have been already updated.

selenium alert automatically click accept with IE driver

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?

Twython: How to update profile banner?

What am I doing wrong?
twitter = twython.Twython(api_key, api_secret, access_token, token_secret)
banner_file = open('banner.jpg', 'rb')
twitter.update_profile_banner_image(banner=banner_file)
Calling this returns:
Traceback (most recent call last): File
"/usr/local/lib/python3.5/dist-packages/twython/api.py", line 202, in
_request
content = response.json() File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 812,
in json
return complexjson.loads(self.text, **kwargs) File "/usr/lib/python3.5/json/init.py", line 319, in loads
return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char
0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "tuit.py", line 45, in
twitter.update_profile_banner_image(banner=banner) File "/usr/local/lib/python3.5/dist-packages/twython/endpoints.py", line
493, in update_profile_banner_image
return self.post('account/update_profile_banner', params=params) File "/usr/local/lib/python3.5/dist-packages/twython/api.py", line
270, in post
return self.request(endpoint, 'POST', params=params, version=version) File
"/usr/local/lib/python3.5/dist-packages/twython/api.py", line 260, in
request
api_call=url) File "/usr/local/lib/python3.5/dist-packages/twython/api.py", line 205, in
_request
Unable to decode.') twython.exceptions.TwythonError: Response was not valid JSON. Unable to decode.

Error of using urllib.request library in python

i try to read url for using urllib.request library in python.
but there are so many error in shell.
i wrote code following this.
import urllib.request
req=urllib.request
req.urlopen("http://www.naver.com")
but there are some error following this.
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
req.urlopen("http://news.naver.com/")
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 465, in open
response = self._open(req, data)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 483, in _open
'_open', req)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1268, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1243, in do_open
r = h.getresponse()
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1174, in getresponse
response.begin()
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 282, in begin
version, status, reason = self._read_status()
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 251, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
what's wrong??
i don't know why this happening
i use python 3.5.1 and windows8.1 64bit.

Resources