I'm writing a program that will run inside Fusion 360. Fusion 360 uses Python as its scripting language and it provides its own Python. When my program is executed, Fusion 360 loads it within its Python and runs it. Because of that, I don't have any control over the Python environment. It's possible to use additional packages as long as they're local to my program and imported using relative paths but I prefer to use the Python standard library to avoid the extra issues of re-delivering more components and their dependencies.
Fusion 360 is using Python 3.5.3 and I'm trying to make some RESTFUL API calls. On Windows, everything is working as expected, but on Mac it's failing. I was initially trying to use requests and was assuming the failure was with the requests package but someone suggested using urllib instead to stick with the standard library and it's also failing for the same reason.
The code works for most standard websites (google in the example below) but fails for others. In my testing, it always fails when the endpoint is a REST API but it is also failing for github.com so that may be a red herring. This is an area that I have very little experience with and can use some suggestions on how to debug and resolve the issue.
import traceback
import urllib.request
def run(context):
try:
# url = 'https://github.com'
# url = 'https://google.com'
url = 'https://api.github.com'
req = urllib.request.urlopen(url)
print(req.read())
req.close()
except:
print(traceback.format_exc())
As I said before, this is working on Windows but failing on Mac. Here's the trace results of the failure.
Traceback (most recent call last): File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/urllib/request.py", line 1254, in do_open h.request(req.get_method(), req.selector, req.data, headers) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/http/client.py", line 1107, in request self._send_request(method, url, body, headers) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/http/client.py", line 1152, in _send_request self.endheaders(body) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/http/client.py", line 1103, in endheaders self._send_output(message_body) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/http/client.py", line 934, in _send_output self.send(msg) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/http/client.py", line 877, in send self.connect() File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/http/client.py", line 1261, in connect server_hostname=server_hostname) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/ssl.py", line 385, in wrap_socket _context=self) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/ssl.py", line 760, in init self.do_handshake() File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/ssl.py", line 996, in do_handshake self._sslobj.do_handshake() File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/ssl.py", line 641, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:720)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/admin/Dropbox/Scripts/RestfulTest/RestfulTest.py", line 23, in run req = urllib.request.urlopen(url) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/urllib/request.py", line 163, in urlopen return opener.open(url, data, timeout) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/urllib/request.py", line 466, in open response = self._open(req, data) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/urllib/request.py", line 484, in _open '_open', req) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/urllib/request.py", line 444, in _call_chain result = func(*args) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/urllib/request.py", line 1297, in https_open context=self._context, check_hostname=self._check_hostname) File "/Users/admin/Library/Application Support/Autodesk/webdeploy/production/a71844880b03ed71d4a9c581cd70965fd6323ebc/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.5/urllib/request.py", line 1256, in do_open raise URLError(err) urllib.error.URLError: