Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when using venv-exec with the example http-in flow #40

Open
Zebble opened this issue Nov 20, 2024 · 2 comments
Open

TypeError when using venv-exec with the example http-in flow #40

Zebble opened this issue Nov 20, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Zebble
Copy link

Zebble commented Nov 20, 2024

Running node-red 4.0.5 in docker.

Using the example http-in (/url) results in an error in the venv node when triggered:

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle

I've confirmed the pip command nodes work nicely and the virtual environment is created properly. Most everything else I've tested works well.

@404background
Copy link
Owner

Thank you @Zebble for your report to the issue!
I executed flows.json in the examples folder with version 0.5.0 and got an same error.
image

Since the sample was executable in older versions, I think the error occurred when the execution method was changed.
After deleting msg.req and msg.res, I was able to run the page, but the page did not display in the browser.
image
image

If I assign msg.req and msg.res to flow.req and flow.res once and assign them after Python processing, the page is displayed in the browser.
image

I will try to investigate the cause of the error.

Here is the flow.

[{"id":"aeab9cd3bf5d7fef","type":"debug","z":"d6fad9e77ecc8414","name":"debug 287","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":2320,"wires":[]},{"id":"f1cb3fe41dd94f20","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":460,"y":2320,"wires":[["dd049a94d893c70b"]]},{"id":"fa75ba3ec9616df6","type":"http in","z":"d6fad9e77ecc8414","name":"","url":"/url","method":"get","upload":false,"swaggerDoc":"","x":330,"y":2380,"wires":[["8a515ceda5abc0d0","4a6bcb9706fd5b72"]]},{"id":"26d66f28fd4429a4","type":"http response","z":"d6fad9e77ecc8414","name":"","statusCode":"","headers":{"content-type":"text/html"},"x":970,"y":2360,"wires":[]},{"id":"dd049a94d893c70b","type":"venv","z":"d6fad9e77ecc8414","venvconfig":"4657b6fbdbaf6f7e","name":"","code":"import requests\nurl = 'https://example.com/'\n    \ntry:\n    response = requests.get(url)\n\n    if response.status_code == 200:\n        print(response.text)\n    else:\n        print(f\"Failed to retrieve data. Status code: {response.status_code}\")\nexcept requests.RequestException as e:\n    print(f\"An error occurred: {e}\")","continuous":false,"x":630,"y":2320,"wires":[["aeab9cd3bf5d7fef","26c1b0b8033f215a"]]},{"id":"8a515ceda5abc0d0","type":"change","z":"d6fad9e77ecc8414","name":"","rules":[{"t":"move","p":"req","pt":"msg","to":"req","tot":"flow"},{"t":"move","p":"res","pt":"msg","to":"res","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":2380,"wires":[["dd049a94d893c70b","50b973e3eed3f2ef"]]},{"id":"50b973e3eed3f2ef","type":"debug","z":"d6fad9e77ecc8414","name":"debug 289","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":2400,"wires":[]},{"id":"c5c0e59e602d0008","type":"debug","z":"d6fad9e77ecc8414","name":"debug 290","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":2440,"wires":[]},{"id":"26c1b0b8033f215a","type":"change","z":"d6fad9e77ecc8414","name":"","rules":[{"t":"set","p":"req","pt":"msg","to":"req","tot":"flow"},{"t":"set","p":"res","pt":"msg","to":"res","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":2360,"wires":[["26d66f28fd4429a4"]]},{"id":"4a6bcb9706fd5b72","type":"json","z":"d6fad9e77ecc8414","name":"","property":"payload","action":"str","pretty":false,"x":490,"y":2440,"wires":[["c5c0e59e602d0008"]]},{"id":"4657b6fbdbaf6f7e","type":"venv-config","venvname":"pyenv","version":"default"}]

@404background 404background self-assigned this Nov 26, 2024
@404background 404background added the bug Something isn't working label Nov 26, 2024
@Zebble
Copy link
Author

Zebble commented Nov 26, 2024

Thanks @404background !

Glad you were able to replicate the issue. I was able to work around the problem for now using something very similar to what you did but I just saved the entire msg to a flow variable, then re-defined msg before sending it to the python node. I then grabbed the msg flow variable before sending it to the http-out node. All seems to work OK for now.

I did do some further troubleshooting, and looks like the circular reference is a socket which I'm unsure how to fix. I was going to take a look at how other nodes did it before you responded...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants