Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    urllib2.urlopen fails on C4D for Mac

    Cinema 4D SDK
    8
    32
    22.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      m_adam
      last edited by

      Yes the SSL error is only a mac issue

      MAXON SDK Specialist

      Development Blog, MAXON Registered Developer

      1 Reply Last reply Reply Quote 2
      • merkvilsonM
        merkvilson
        last edited by merkvilson

        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?

        1 Reply Last reply Reply Quote 0
        • merkvilsonM
          merkvilson
          last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by m_adam

            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)
            

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            merkvilsonM 1 Reply Last reply Reply Quote 3
            • merkvilsonM
              merkvilson @m_adam
              last edited by

              @m_adam

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

              1 Reply Last reply Reply Quote 0
              • merkvilsonM
                merkvilson
                last edited by

                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

                1 Reply Last reply Reply Quote 0
                • M
                  m_adam
                  last edited by

                  @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

                  MAXON SDK Specialist

                  Development Blog, MAXON Registered Developer

                  1 Reply Last reply Reply Quote 1
                  • merkvilsonM
                    merkvilson
                    last edited by

                    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 😂

                    1 Reply Last reply Reply Quote 0
                    • merkvilsonM
                      merkvilson
                      last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • lasselauchL
                        lasselauch
                        last edited by lasselauch

                        Hey everyone,

                        i am having this problem where I want to download an assets (zipfile) from a private repo on GitHub.

                        I've started to develop it with requests from there everything worked fine... now I am trying to port it to urllib2 for C4D but it doesn't work anymore...

                        'Accept': 'application/octet-stream' will always result in: HTTP Error 415: Unsupported Media Type

                        If I get rid of 'Accept': 'application/octet-stream' it will give me the application/json

                                headers = {
                                    'Authorization': 'token %s' % (MYTOKEN),
                                    'Accept': 'application/octet-stream',
                                }
                        
                                url = 'https://api.github.com/repos/USER/REPO/releases/ID'
                        
                                request = urllib2.Request(url, headers=headers)
                                response = urllib2.urlopen(request)
                        
                                print response.read()
                        
                                #GIVES ME:
                                #urllib2.HTTPError: HTTP Error 415: Unsupported Media Type
                        

                        Any idea how to avoid the HTTP Error 415 and download the zip to disk?
                        Really hard to find something about this anywhere...

                        Any help is appreciated.

                        Thanks,
                        Lasse

                        1 Reply Last reply Reply Quote 0
                        • M
                          mp5gosu
                          last edited by mp5gosu

                          Hi Lasse,

                          you're probably having some issues with authorization.
                          You're getting a JSON response which may indicate that your requested URL cannot be delivered.
                          What's the content of the reponse if you print it?
                          Does it happen with a public repo as well?

                          Best,
                          Robert

                          lasselauchL 1 Reply Last reply Reply Quote 0
                          • lasselauchL
                            lasselauch @mp5gosu
                            last edited by

                            @mp5gosu
                            Hi Robert!

                            Haven't tested it with a public repo yet, but I'll bet its going to work ... the print of the response gives me:

                            urllib2.HTTPError: HTTP Error 415: Unsupported Media Type

                            which I can't find much info for ...

                            1 Reply Last reply Reply Quote 0
                            • M
                              mp5gosu
                              last edited by mp5gosu

                              By the way, the URL you provided doesn't reflect GitHubs scheme. It is actually https://api.github.com/USER/REPO/releases/ID

                              lasselauchL 1 Reply Last reply Reply Quote 0
                              • lasselauchL
                                lasselauch @mp5gosu
                                last edited by

                                @mp5gosu Yep, the link is coming from the provided JSON data. Also removing the repo from the link gives me the same error!
                                Is it possible that this has something to do with 'Accept': 'application/octet-stream'? Isn't it possible to stream with urllib2?

                                1 Reply Last reply Reply Quote 0
                                • M
                                  mp5gosu
                                  last edited by

                                  Hey Lasse,

                                  sorry - removing "repos" is actually wrong when using api access, my bad.
                                  I can now also comprehend your problem. I'm going to dig a little deeper. 😉

                                  1 Reply Last reply Reply Quote 0
                                  • M
                                    mp5gosu
                                    last edited by

                                    Hey again. Managed to download it when using the zipball or tarball URLs. Weird though, that it responds with 415 when using the asset id directly.

                                    lasselauchL 1 Reply Last reply Reply Quote 0
                                    • lasselauchL
                                      lasselauch @mp5gosu
                                      last edited by lasselauch

                                      @mp5gosu interesting... i guess shipping and importing the requests module with the plugin, is too much of a hassle... really hard to find any further informations on this... strange...

                                      1 Reply Last reply Reply Quote 0
                                      • M
                                        mp5gosu
                                        last edited by

                                        I dare to say that urllib2 is the culprit here. I don't have any problems using other libs or tool in the exact same way. curl works out of the box for example.

                                        1 Reply Last reply Reply Quote 0
                                        • lasselauchL
                                          lasselauch
                                          last edited by

                                          yeah, had no luck either... okay, so I'm probably back to importing requests as 3rd party module. 🙂

                                          Thanks for the quick help, Robert!

                                          1 Reply Last reply Reply Quote 0
                                          • M
                                            mp5gosu
                                            last edited by

                                            Using requests package would be the solution I guess. Even the docs state that they are auperior on high level access.
                                            The web says that urllib2 is broken in so many ways due to its age.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post