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

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

Closed
5 tasks done
rickythink opened this issue Sep 5, 2024 · 6 comments
Closed
5 tasks done

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

rickythink opened this issue Sep 5, 2024 · 6 comments
Labels
🐞 bug Something isn't working

Comments

@rickythink
Copy link
Contributor

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

Copy link

dosubot bot commented 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 dosubot bot added the 🐞 bug Something isn't working label Sep 5, 2024
@rickythink
Copy link
Contributor Author

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

Copy link

dosubot bot commented 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.

@rickythink
Copy link
Contributor Author

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

@crazywoola
Copy link
Member

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

@rickythink
Copy link
Contributor Author

closed by #8397

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

No branches or pull requests

2 participants