PyCharm op Mac werkt niet

Pagina: 1
Acties:

Vraag


Acties:
  • 0 Henk 'm!

  • Aviv1
  • Registratie: Januari 2018
  • Laatst online: 04-02 22:08
Hallo,

Al de hele avond probeer ik een issue te op te lossen met PyCharm maar ik krijg het niet voor elkaar. De code werkt prima op mijn Windows machine maar niet op mijn Macbook.

Python:
1
2
3
4
5
6
7
8
9
10
from urllib.request import urlopen, urlretrieve
import bs4

url = "https://www.blabla.com/"

html_file = urlopen(url).read()
html_parse = bs4.BeautifulSoup(html_file, 'html.parser')
all_container = html_parse('div', 'wlv-item__word-box')

[..]


Error:

Python:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/usr/local/bin/python3 /Users/gebruiker/PycharmProjects/crawl/crawl.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1392, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/gebruiker/PycharmProjects/crawl/crawl.py", line 6, in <module>
    html_file = urlopen(url).read()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 563, in error
    result = self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 755, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)>

Process finished with exit code 1


Als ik het via Terminal probeer, krijg ik de volgende error:

code:
1
2
3
4
5
MacBook-Pro-van-gebruiker:desktop gebr$ python crawl.py
Traceback (most recent call last):
  File "crawl.py", line 1, in <module>
    from urllib.request import urlopen, urlretrieve
ImportError: No module named request


Wat heb ik geprobeerd?

* Python 3.7 opnieuw geïnstalleerd
* PyCharm opnieuw geïnstalleerd
* System interpretator opnieuw toegevoegd

Dit alles werkt niet. Heeft iemand enig idee wat ik nog kan proberen?

Groet!

Let me share my screen...

Alle reacties


Acties:
  • 0 Henk 'm!

  • Matszs
  • Registratie: Juli 2010
  • Laatst online: 05-10 21:06

Matszs

><>

Die voor in de terminal: Voer eens het command 'python --version' uit, ik denk namelijk dat je daarmee python 2.x aanroept, en niet python 3 die je wel gebruikt in je PyCharm. (waarschijnlijk moet je hem aanroepen met 'python3 crawl.py')

Bij je andere fout gaat het mis bij dit stukje: "certificate verify failed: self signed certificate in certificate chain", hierop zou je kunnen googlen en kom je bijvoorbeeld hier op uit: https://stackoverflow.com...-certificate-verify-error

Acties:
  • 0 Henk 'm!

  • Aviv1
  • Registratie: Januari 2018
  • Laatst online: 04-02 22:08
Matszs schreef op vrijdag 8 maart 2019 @ 00:21:
Die voor in de terminal: Voer eens het command 'python --version' uit, ik denk namelijk dat je daarmee python 2.x aanroept, en niet python 3 die je wel gebruikt in je PyCharm. (waarschijnlijk moet je hem aanroepen met 'python3 crawl.py')

Bij je andere fout gaat het mis bij dit stukje: "certificate verify failed: self signed certificate in certificate chain", hierop zou je kunnen googlen en kom je bijvoorbeeld hier op uit: https://stackoverflow.com...-certificate-verify-error
Het antwoord in de terminal is Python 2.7.10
Maar in de IDE heb ik Python 3 gekozen..

Let me share my screen...


Acties:
  • 0 Henk 'm!

  • Room42
  • Registratie: September 2001
  • Niet online
Aviv1 schreef op vrijdag 8 maart 2019 @ 00:42:
[...]

Het antwoord in de terminal is Python 2.7.10
Maar in de IDE heb ik Python 3 gekozen..
En op Windows? ;)

En in de terminal moet je wellicht 'python3' hebben of de juiste module ook voor Python 2.7 installeren.

[ Voor 19% gewijzigd door Room42 op 08-03-2019 00:53 ]

"Technological advancements don't feel fun anymore because of the motivations behind so many of them." Bron


Acties:
  • 0 Henk 'm!

  • Aviv1
  • Registratie: Januari 2018
  • Laatst online: 04-02 22:08
Room42 schreef op vrijdag 8 maart 2019 @ 00:50:
[...]

En op Windows? ;)

En in de terminal moet je wellicht 'python3' hebben of de juiste module ook voor Python 2.7 installeren.
Klopt. Met 'python3' kan ik het inderdaad wel runnen vanuit Terminal. Maar dan blijft de SSL issue bestaan. Ik begrijp er nog niet veel van, maar probeer het hiermee op te lossen door SSL tijdelijk uit te zetten: "opting out"

zie: https://www.python.org/dev/peps/pep-0476/

/edit:

Python:
1
2
3
4
5
6
7
8
9
10
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context


Dit lijkt iets te doen... geen error iig meer

[ Voor 29% gewijzigd door Aviv1 op 08-03-2019 01:10 ]

Let me share my screen...


Acties:
  • 0 Henk 'm!

  • Room42
  • Registratie: September 2001
  • Niet online
@Aviv1 Matszs in "PyCharm op Mac werkt niet" gaf toch al dat antwoord? ;)

Het probleem is dat de URL die je gebruikt een self-signed certificaat gebruikt, dus standaard niet vertrouwd wordt. Een geldig certificaat wordt namelijk door een vertrouwde Certificat Authority uitgegeven (c.q. ondertekend).

In jouw geval is nu dus even het makkelijkst om dat maar te negeren. En ja, jouw link, onder https://www.python.org/dev/peps/pep-0476/#opting-out, beschrijft dat inderdaad.

edit:
Mooi :)

"Technological advancements don't feel fun anymore because of the motivations behind so many of them." Bron


Acties:
  • 0 Henk 'm!

  • Kettrick
  • Registratie: Augustus 2000
  • Laatst online: 00:14

Kettrick

Rantmeister!

Welke website probeer je te openen?, het probleem zit hem niet in python versies maar in je ssl certificaten. Het lijkt er op dat je een self signed certificaat gebruikt, je moet ofwel zorgen dat dat certificaat geinstalleerd wordt onder osx of je moet de cerficicaat controle uitschakelen zoals bijvoorbeeld hier uitgelegd wordt https://stackoverflow.com...e-ssl-check-in-python-3-x
Pagina: 1