אשמח לעזרה בקוד פייתון
-
@yossiz תודה רבה לך!
אל תטרח יותר מידי מחר אני אשאל את המרצה שלי...
אגב אני הבנתי שזה קשור למודול requests אבל הוא נתן שגיאות מהקבצים של המודול וזה לא משהו שאני מבין...
לילה טוב ושוב תודה -
@Android כנראה שהמרצה שלך עושה פחות בעיות מהזקנים הממורמרים של תחומים
תעדכן אותנו בתשובה בבקשה!
-
@yossiz כתב באשמח לעזרה בקוד פייתון:
תעדכן אותנו בתשובה בבקשה!
בתשובה של מה? של התרגיל?
למיטב זכרוני הוא אמר שאחת הדרכים היא לקבל את דף הhtml של ההורדה ולנתח אותו ומשם להוציא את הקישור, אבל זה מסובך בשביל שעה מאוחרת כזו...
-
@yossiz כתב באשמח לעזרה בקוד פייתון:
@Android התכוונתי התשובה של מה גורם לשגיאה הזאת
לדעתי אני יעזוב את הכיוון הזה וינסה בכיוון השני (
)
אבל יכול להיות שבגלל שבכתובת url שנתתי לו יש.pdf אז הוא מסתבך עם זה -
@Android אם כבר, אז אעיר גם כן שבקוד שלך אתה ניגש ישירות ל-PDF של הגליון אם כן אין צורך וגם אי אפשר להשתמש ב-BeautifulSoup שמיועד לניתוח HTML
@yossiz גם זה נכון, לא יודע בשביל מה עשיתי את זה
משום מה גם זה לא עובדurl = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\h\Desktop\issues\8", "w") as file_net: file_net.write(f"{url.text}")
-
@yossiz גם זה נכון, לא יודע בשביל מה עשיתי את זה
משום מה גם זה לא עובדurl = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\h\Desktop\issues\8", "w") as file_net: file_net.write(f"{url.text}")
-
@Android אצלי הקוד לא זורק שגיאות
ה-PDF אומנם לא נשמר תקין, מן הסתם כי משהו משתבש בהמרה של בינארי למחרוזת, תשתמש ב-content
במקוםtext
with open(fr"C:\Users\h\Desktop\issues\8", "wb") as file_net: file_net.write(url.content)
-
@yossiz
ניסיתי את זה וזה זורק את אותן השגיאותurl = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\h\Desktop\issues\8", "wb") as file_net: file_net.write(url.content)
@Android כתב באשמח לעזרה בקוד פייתון:
@yossiz
ניסיתי את זה וזה זורק את אותן השגיאותurl = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\h\Desktop\issues\8", "wb") as file_net: file_net.write(url.content)
שהן? עברתי על השרשור ולא ראיתי שהבאת בצורה ברורה קוד + פלט שגיאה, רק ציטוטים של @yossiz על הגרסה הראשונית של הקוד
כיוון שאינני יודע מה השגיאה, אני יכול לומר רק שהקוד הזה עובד ומוריד את קובץ הPDF לשולחן העבודה:import requests url = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\shlomo\Desktop\DigitalWhisper8.pdf", "wb") as file_net: file_net.write(url.content)
עריכה: נראה שהעברת ל
open
נתיב לתקיה ולא נתיב מלא (תקיה + שם קובץ), ואם כן אני מנחש שקיבלת שגיאתIsADirectoryError: [Errno 21] Is a directory
. אני צודק? -
@Android כתב באשמח לעזרה בקוד פייתון:
@yossiz
ניסיתי את זה וזה זורק את אותן השגיאותurl = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\h\Desktop\issues\8", "wb") as file_net: file_net.write(url.content)
שהן? עברתי על השרשור ולא ראיתי שהבאת בצורה ברורה קוד + פלט שגיאה, רק ציטוטים של @yossiz על הגרסה הראשונית של הקוד
כיוון שאינני יודע מה השגיאה, אני יכול לומר רק שהקוד הזה עובד ומוריד את קובץ הPDF לשולחן העבודה:import requests url = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\shlomo\Desktop\DigitalWhisper8.pdf", "wb") as file_net: file_net.write(url.content)
עריכה: נראה שהעברת ל
open
נתיב לתקיה ולא נתיב מלא (תקיה + שם קובץ), ואם כן אני מנחש שקיבלת שגיאתIsADirectoryError: [Errno 21] Is a directory
. אני צודק?@צדיק-תמים בהתחלה הייתה תמונה אבל היא הוסרה
-
@Android כתב באשמח לעזרה בקוד פייתון:
@yossiz
ניסיתי את זה וזה זורק את אותן השגיאותurl = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\h\Desktop\issues\8", "wb") as file_net: file_net.write(url.content)
שהן? עברתי על השרשור ולא ראיתי שהבאת בצורה ברורה קוד + פלט שגיאה, רק ציטוטים של @yossiz על הגרסה הראשונית של הקוד
כיוון שאינני יודע מה השגיאה, אני יכול לומר רק שהקוד הזה עובד ומוריד את קובץ הPDF לשולחן העבודה:import requests url = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") with open(fr"C:\Users\shlomo\Desktop\DigitalWhisper8.pdf", "wb") as file_net: file_net.write(url.content)
עריכה: נראה שהעברת ל
open
נתיב לתקיה ולא נתיב מלא (תקיה + שם קובץ), ואם כן אני מנחש שקיבלת שגיאתIsADirectoryError: [Errno 21] Is a directory
. אני צודק?@צדיק-תמים כתב באשמח לעזרה בקוד פייתון:
import requests
url = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf")
with open(fr"C:\Users\shlomo\Desktop\DigitalWhisper8.pdf", "wb") as file_net: file_net.write(url.content)עכשיו ניסיתי את זה וזה לא עובד לי, מוזר
אלה השגיאות:
Traceback (most recent call last): File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen httplib_response = self._make_request( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request self._validate_conn(conn) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn conn.connect() File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connection.py", line 414, in connect self.sock = ssl_wrap_socket( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl( File "C:\Users\h\Desktop\Python\pythonProject\venv\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\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket return self.sslsocket_class._create( File "C:\Users\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create self.do_handshake() File "C:\Users\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\adapters.py", line 440, in send resp = conn.urlopen( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen retries = retries.increment( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.digitalwhisper.co.il', port=443): Max retries exceeded with url: /files/Zines/0x08/DigitalWhisper8.pdf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)'))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\h\desktop\python\pythonProject\BeautifulSoup4.py", line 10, in <module> url = requests.get("http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 529, in request resp = self.send(prep, **send_kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 667, in send history = [resp for resp in gen] File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 667, in <listcomp> history = [resp for resp in gen] File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 237, in resolve_redirects resp = self.send( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 645, in send r = adapter.send(request, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\adapters.py", line 517, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='www.digitalwhisper.co.il', port=443): Max retries exceeded with url: /files/Zines/0x08/DigitalWhisper8.pdf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
-
@צדיק-תמים כתב באשמח לעזרה בקוד פייתון:
import requests
url = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf")
with open(fr"C:\Users\shlomo\Desktop\DigitalWhisper8.pdf", "wb") as file_net: file_net.write(url.content)עכשיו ניסיתי את זה וזה לא עובד לי, מוזר
אלה השגיאות:
Traceback (most recent call last): File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen httplib_response = self._make_request( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request self._validate_conn(conn) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn conn.connect() File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connection.py", line 414, in connect self.sock = ssl_wrap_socket( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl( File "C:\Users\h\Desktop\Python\pythonProject\venv\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\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket return self.sslsocket_class._create( File "C:\Users\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create self.do_handshake() File "C:\Users\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\adapters.py", line 440, in send resp = conn.urlopen( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen retries = retries.increment( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.digitalwhisper.co.il', port=443): Max retries exceeded with url: /files/Zines/0x08/DigitalWhisper8.pdf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)'))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\h\desktop\python\pythonProject\BeautifulSoup4.py", line 10, in <module> url = requests.get("http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 529, in request resp = self.send(prep, **send_kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 667, in send history = [resp for resp in gen] File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 667, in <listcomp> history = [resp for resp in gen] File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 237, in resolve_redirects resp = self.send( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 645, in send r = adapter.send(request, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\adapters.py", line 517, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='www.digitalwhisper.co.il', port=443): Max retries exceeded with url: /files/Zines/0x08/DigitalWhisper8.pdf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
-
@צדיק-תמים כתב באשמח לעזרה בקוד פייתון:
import requests
url = requests.get(f"http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf")
with open(fr"C:\Users\shlomo\Desktop\DigitalWhisper8.pdf", "wb") as file_net: file_net.write(url.content)עכשיו ניסיתי את זה וזה לא עובד לי, מוזר
אלה השגיאות:
Traceback (most recent call last): File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen httplib_response = self._make_request( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request self._validate_conn(conn) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn conn.connect() File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connection.py", line 414, in connect self.sock = ssl_wrap_socket( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl( File "C:\Users\h\Desktop\Python\pythonProject\venv\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\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket return self.sslsocket_class._create( File "C:\Users\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create self.do_handshake() File "C:\Users\h\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\adapters.py", line 440, in send resp = conn.urlopen( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen retries = retries.increment( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.digitalwhisper.co.il', port=443): Max retries exceeded with url: /files/Zines/0x08/DigitalWhisper8.pdf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)'))) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\h\desktop\python\pythonProject\BeautifulSoup4.py", line 10, in <module> url = requests.get("http://digitalwhisper.co.il/files/Zines/0x08/DigitalWhisper8.pdf") File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 529, in request resp = self.send(prep, **send_kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 667, in send history = [resp for resp in gen] File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 667, in <listcomp> history = [resp for resp in gen] File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 237, in resolve_redirects resp = self.send( File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\sessions.py", line 645, in send r = adapter.send(request, **kwargs) File "C:\Users\h\Desktop\Python\pythonProject\venv\lib\site-packages\requests\adapters.py", line 517, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='www.digitalwhisper.co.il', port=443): Max retries exceeded with url: /files/Zines/0x08/DigitalWhisper8.pdf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
@Android רק הערה, נראה שאתה רואה פלט ארוך וחושב שהשגיאה מאוד מסובכת, למעשה זה מאוד פשוט, הפלט מציג את הקוד שלך ששלח לקוד אחר בספריה כלשהי ששלחה לקוד אחר וכן הלאה עד לאיפה שההרצה נתקעה - ככה שמספיק לקרוא רק את 2-3 השורות האחרונות בפלט השגיאה - במקרה שלך זה השורות האלו
raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='www.digitalwhisper.co.il', port=443): Max retries exceeded with url: /files/Zines/0x08/DigitalWhisper8.pdf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
וזה, כמו שאמר @צדיק-תמים מצביע ככל הנראה על תעודת אבטחה חסרה
-
@צדיק-תמים יש לי סינון של רימון, זה גם יכול להוות בעיה?
אם כן איך אני מתקין את התעודה?
תודה -
@צדיק-תמים יש לי סינון של רימון, זה גם יכול להוות בעיה?
אם כן איך אני מתקין את התעודה?
תודה -
@צדיק-תמים יש לי סינון של רימון, זה גם יכול להוות בעיה?
אם כן איך אני מתקין את התעודה?
תודה -
@Android באמצעות אחת מב' השיטות הנוספות שבקישור שהבאתי (הראשונה לא רלוונטית כיוון שלא ידוע לי על קובץ באנדל תעודות של רימון), רק שתשתמש בתעודה של רימון https://www.rimon.net.il/sites/www1.rimon.net.il/files/myca.crt
@צדיק-תמים את זה?
אני יצטרך להוסיף את זה לכל סקריפט? -
@צדיק-תמים את זה?
אני יצטרך להוסיף את זה לכל סקריפט? -
@Android בצורה הזאת כן. אבל יש שם שיטה נוספת...
-
@Android בצורה הזאת כן. אבל יש שם שיטה נוספת...
@צדיק-תמים הרצתי את זה ועדיין לא עובד
type "C:\Users\h\Downloads\myca.crt">>"C:\Users\h\AppData\Local\Programs\Python\Python310\lib\site-packages\certifi\cacert.pem"