API Requests stop working when reopening Toe file

Hi, I work on a project using requests to get online Data about UV Index. I have no problem getting the data when I start a new Touchdesigner project and write my code with the request library. But the moment I close it and open it again nothing works anymore…

This is the errors in the console
Traceback (most recent call last):
File “</project1/request:op(‘/project1/request’).run()>”, line 1
td.Error: File “/project1/request”, line 1
r = previousimport(*args, **kw)
File “C:\Program Files\Derivative\TouchDesigner.2020.41040\bin\lib\site-packages\requests_init_.py”, line 43
import urllib3
r = previousimport(*args, **kw)
File “C:\Program Files\Derivative\TouchDesigner.2020.41040\bin\lib\site-packages\urllib3_init_.py”, line 8
from .connectionpool import (
r = previousimport(*args, **kw)
File “C:\Program Files\Derivative\TouchDesigner.2020.41040\bin\lib\site-packages\urllib3\connectionpool.py”, line 29
from .connection import (
r = previousimport(*args, **kw)
File “C:\Program Files\Derivative\TouchDesigner.2020.41040\bin\lib\site-packages\urllib3\connection.py”, line 38
from .util.ssl_ import (
r = previousimport(*args, **kw)
File “C:\Program Files\Derivative\TouchDesigner.2020.41040\bin\lib\site-packages\urllib3\util_init_.py”, line 5
from .response import is_fp_closed
ImportError: cannot import name ‘is_fp_closed’ from ‘/project1/response’ (/project1/response)
Results of run operation resulted in exception.

This is the Toe file. It is a very simple script. Do you guys have any ideas why this is happening. I followed the step to install the request library from this post : Help with installing requests module Python . And as I said everything is working fine if I start a new project and copy paste my code from the non-working one.

** I Tried to uninstall and reinstall an older version of Python and nothing as change.
API.toe (5.0 KB)
Thanks for you help!

Hey Louis,

I can repeat this error and we’ll investigate what’s going on there. Theoretically you don’t require an external python package for this as the requests library is included with the default TouchDesigner installation.

A quick way around this and maybe a good TouchDesigner workflow could be using the webClient DAT instead of scripting it. The attached file contains the same routine using this DAT. It comes with a callback so you can process the data right when it is received. To get it to work ,just replace the appid with your personal one.

Let me know if this makes sense
cheers
Markus
API.6.toe (5.4 KB)

Hey @louislp19,

not quite sure yet why, but somehow the DAT called response conflicts with your python variable response = requests.get(...)
What works for me is just renaming the DAT from response to response1.

Edit: What is happening is that the loaded request library itself has an import call to a module called response. Currently imports in TouchDesigner search the local path - the network - first and in your case come across a DAT called response.
So the solution is to simply rename the DAT response to anything else and things should start working.

Why does it work initially? If import requests is run at anytime before the response DAT has been created, the requests library is successfully imported and referenced locally so that any import statements after will be ignored. Similarly it starts working if you open the textport and run import requests from there as this import is done relative to the root which also does not contain the DAT response.

cheers
Markus

Wow thank you for the very complete explanation of my issue. I will use the Webclient Dat in the future wich is simpler to use. Also I understand much more the cause of my problem.

Louis