The requests module in sandbox doesn't function well #5400

Closed
opened 2026-02-21 18:10:48 -05:00 by yindo · 6 comments
Owner

Originally created by @rickythink on GitHub (Sep 5, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.3

Cloud or Self Hosted

Cloud, Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

  1. Create a sandbox node
  2. Add such code below
import requests

def main() -> dict:
    url = "https://google.com"
    response = requests.get(url)
image
  1. Get error
    image

✔️ Expected Behavior

This happens both on Cloud & self-host

Actual Behavior

No response

Originally created by @rickythink on GitHub (Sep 5, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.3 ### Cloud or Self Hosted Cloud, Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce 1. Create a sandbox node 2. Add such code below ``` import requests def main() -> dict: url = "https://google.com" response = requests.get(url) ``` <img width="376" alt="image" src="https://github.com/user-attachments/assets/b4d34fa1-e79b-456e-9a59-99a8df5583b1"> 3. Get error <img width="360" alt="image" src="https://github.com/user-attachments/assets/f0239fdb-d154-41aa-9b0f-97df00f5df0a"> ### ✔️ Expected Behavior This happens both on Cloud & self-host ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:10:48 -05:00
yindo closed this issue 2026-02-21 18:10:48 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 5, 2024):

I found two similar discussions that might be relevant to your issue:

  1. (bug)dify cloud Version 0.6.12-fix1 版本工作流中的代码执行单元无法正常使用requests which was last updated on 2024-08-03.
  2. Sandbox import error: ModuleNotFoundError: No module named 'requests' error: exit status 255 which was last updated on 2024-06-04.

The issue you're encountering with the requests module in the sandbox environment is due to missing character detection dependencies (chardet or charset_normalizer). These dependencies are not listed in the pyproject.toml file under the [tool.poetry.dependencies] section. To resolve this, you need to add either chardet or charset_normalizer to the dependencies in the pyproject.toml file. Here is how you can do it:

[tool.poetry.dependencies]
# existing dependencies
chardet = "~5.1.0"  # Add this line to include chardet
# or
charset_normalizer = "~3.2.0"  # Add this line to include charset_normalizer

Make sure to add only one of these dependencies, as requests can use either for character encoding detection [1].

Additionally, there are known limitations regarding the use of external libraries like requests in the sandbox environment. The sandboxed execution environment restricts making network requests to ensure security [2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 5, 2024): <!-- Answer --> I found two similar discussions that might be relevant to your issue: 1. [(bug)dify cloud Version 0.6.12-fix1 版本工作流中的代码执行单元无法正常使用requests](https://github.com/langgenius/dify/discussions/6035) which was last updated on 2024-08-03. 2. [Sandbox import error: ModuleNotFoundError: No module named 'requests' error: exit status 255](https://github.com/langgenius/dify/discussions/4854) which was last updated on 2024-06-04. The issue you're encountering with the `requests` module in the sandbox environment is due to missing character detection dependencies (`chardet` or `charset_normalizer`). These dependencies are not listed in the `pyproject.toml` file under the `[tool.poetry.dependencies]` section. To resolve this, you need to add either `chardet` or `charset_normalizer` to the dependencies in the `pyproject.toml` file. Here is how you can do it: ```toml [tool.poetry.dependencies] # existing dependencies chardet = "~5.1.0" # Add this line to include chardet # or charset_normalizer = "~3.2.0" # Add this line to include charset_normalizer ``` Make sure to add only one of these dependencies, as `requests` can use either for character encoding detection <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/pyproject.toml)</sup>. Additionally, there are known limitations regarding the use of external libraries like `requests` in the sandbox environment. The sandboxed execution environment restricts making network requests to ensure security <sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/code.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@rickythink commented on GitHub (Sep 5, 2024):

Could this issue be related to the removal of “Advanced Dependencies” from the panel?

@rickythink commented on GitHub (Sep 5, 2024): Could this issue be related to the removal of “Advanced Dependencies” from the panel?
Author
Owner

@dosubot[bot] commented on GitHub (Sep 5, 2024):

Yes, the issue could be related to the removal of “Advanced Dependencies” from the panel. The AdvancedSetting component, which is part of the panel, includes various advanced settings such as memory settings, instruction changes, and other configurations. If this component or its dependencies were removed, it could potentially cause issues in the functionality of the panel.

Here is the relevant part of the code that includes the AdvancedSetting component:

<Field
  title={t(`${i18nPrefix}.advancedSetting`)}
  supportFold
>
  <AdvancedSetting
    hideMemorySetting={!isChatMode}
    instruction={inputs.instruction}
    onInstructionChange={handleInstructionChange}
    memory={inputs.memory}
    onMemoryChange={handleMemoryChange}
    readonly={readOnly}
    isChatApp={isChatMode}
    isChatModel={isChatModel}
    hasSetBlockStatus={hasSetBlockStatus}
    nodesOutputVars={availableVars}
    availableNodes={availableNodesWithParent}
  />
</Field>

If the AdvancedSetting component or its dependencies were removed, it could lead to issues in the panel's functionality [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 5, 2024): <!-- Answer --> Yes, the issue could be related to the removal of “Advanced Dependencies” from the panel. The `AdvancedSetting` component, which is part of the panel, includes various advanced settings such as memory settings, instruction changes, and other configurations. If this component or its dependencies were removed, it could potentially cause issues in the functionality of the panel. Here is the relevant part of the code that includes the `AdvancedSetting` component: ```tsx <Field title={t(`${i18nPrefix}.advancedSetting`)} supportFold > <AdvancedSetting hideMemorySetting={!isChatMode} instruction={inputs.instruction} onInstructionChange={handleInstructionChange} memory={inputs.memory} onMemoryChange={handleMemoryChange} readonly={readOnly} isChatApp={isChatMode} isChatModel={isChatModel} hasSetBlockStatus={hasSetBlockStatus} nodesOutputVars={availableVars} availableNodes={availableNodesWithParent} /> </Field> ``` If the `AdvancedSetting` component or its dependencies were removed, it could lead to issues in the panel's functionality <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/question-classifier/panel.tsx)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@rickythink commented on GitHub (Sep 5, 2024):

And the pic below shows the site-packages of sandbox v0.2.6 in /usr/local/lib/python3.10/site-packages

image

It does contain requests and charset_normalizer, but I have no idea why it fails

@rickythink commented on GitHub (Sep 5, 2024): And the pic below shows the site-packages of sandbox v0.2.6 in `/usr/local/lib/python3.10/site-packages` <img width="1900" alt="image" src="https://github.com/user-attachments/assets/1ba13cf9-264d-4ab6-b74e-cf70c095a513"> It does contain `requests` and `charset_normalizer`, but I have no idea why it fails
Author
Owner

@crazywoola commented on GitHub (Sep 5, 2024):

FYI, In 0.2.6, we no longer need to include it in advance settings. I think you can try httpx.

@crazywoola commented on GitHub (Sep 5, 2024): FYI, In 0.2.6, we no longer need to include it in advance settings. I think you can try httpx.
Author
Owner

@rickythink commented on GitHub (Sep 13, 2024):

closed by https://github.com/langgenius/dify/pull/8397

@rickythink commented on GitHub (Sep 13, 2024): closed by https://github.com/langgenius/dify/pull/8397
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5400