urllib2.urlopen fails on C4D for Mac



  • Edit: Here is a solution by Maxime:

    import c4d
    import urllib2
    import os
    
    f = os.path.join(os.path.dirname(c4d.storage.GeGetStartupApplication()), "resource", "ssl", "cacert.pem")
    urllib2.urlopen("https://google.com", cafile=f)
    




  • Hi, @merkvilson thanks for contacting us.

    Unfortunately, this is an already a known issue and it's not fixed yet.
    You may find some workaround by googling the error message, but this indeed introduce some security issue so we can't recommend this as a correct workaround.

    Cheers,
    Maxime.



  • Does this apply only to Mac devices?



  • Ok. It seems like this problem occurs only on Mac devices.



  • Yes the SSL error is only a mac issue



  • It seems like there are two ways of solving this problem.

    • Via PIP: pip install --upgrade certifi
    • Via Cerificates.command open /Applications/Python\ 3.6/Install\ Certificates.command (Yes. I know C4D works only with python 2.7 😅 )

    Is it possible to execute these codes directly from python plugin?



  • As I remember, there is a pip module which can be imported via import pip command in python code and then install the desired modules but will it work with C4D's python implementation?



  • Hi @merkvilson, I indeed overlooked the issue, since in all topic it's only Python 3.6, I didn't tried.

    But in MacOs, certifi is not installed (which cause the issue), but you can directly get the certificate file to make it works as expected. Here the code which works on mac and windows.

    import c4d
    import os
    import ssl
    import urllib
    
    f = os.path.join(os.path.dirname(c4d.storage.GeGetStartupApplication()), "resource", "ssl", "cacert.pem")
    context = ssl.create_default_context(cafile=f)
    urllib.urlopen("https://google.com",context=context)
    

    Or with urllib2

    import c4d
    import urllib2
    import os
    
    f = os.path.join(os.path.dirname(c4d.storage.GeGetStartupApplication()), "resource", "ssl", "cacert.pem")
    urllib2.urlopen("https://google.com", cafile=f)
    


  • @m_adam

    Thanks, Maxime! I'll check it as soon as one of the beta testers will be available online to test it out.



  • I'm getting this error message on windows pc. I guess this is expected behavior on windows, right?
    urllib2.HTTPError: HTTP Error 405: METHOD NOT ALLOWED



  • @merkvilson said in C4D's python implementation on Mac and PC:

    urllib2.HTTPError: HTTP Error 405: METHOD NOT ALLOWED

    Does it happen on all websites? Or only a specific one? Could you try to open https://google.com
    Here it's working nicely on windows/mac



  • I tried again and it worked perfectly.
    I'm not sure what caused the previous problem. I probably did something wrong.
    I'm still testing it on my windows pc, and I'm not getting any errors.
    I guess this thread will be marked as solved in a few minutes 😂



  • Code worked on all of my beta testers' mac and windows devices. 😁 👌
    Thanks, Maxime!