Closed dingidng closed 2 days ago
To resolve the "No module named 'pymysql'" error (exit status 255) when using the code execution module on the front-end page in a self-hosted Dify version 0.8.2 environment, you need to ensure that the pymysql
module is installed in the environment where the code execution is taking place.
You can install the pymysql
module using pip. Here is the command to install it:
pip install pymysql
If you are using a virtual environment, make sure to activate it before running the above command.
Additionally, ensure that the sandbox service used for code execution has access to the pymysql
module. If the sandbox service is running in a containerized environment, you may need to update the container image to include the pymysql
module.
Here is an example of how you might modify a Dockerfile to include the pymysql
module:
FROM python:3.9-slim
# Install pymysql
RUN pip install pymysql
# Copy your application code
COPY . /app
# Set the working directory
WORKDIR /app
# Run your application
CMD ["python", "your_application.py"]
After updating the Dockerfile, rebuild the Docker image and redeploy the container.
By ensuring that the pymysql
module is installed in the appropriate environment, you should be able to resolve the "No module named 'pymysql'" error [1].
To continue talking to Dosu, mention @dosu.
Run failed: Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 649, in connect
sock = socket.create_connection(
File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection
raise err
File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/sandbox/sandbox-python/tmp/41da4196_adf7_4fa0_a725_50afabb2ed90.py", line 48, in <module>
File "<string>", line 7, in <module>
File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 361, in init
self.connect()
File "/usr/local/lib/python3.10/site-packages/pymysql/connections.py", line 716, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '10.80.2.195' ([Errno 101] Network is unreachable)")
error: exit status 255
I encountered a new error, remote mysql cannot be linked, but it can be successfully operated on my local computer
The error OSError: [Errno 101] Network is unreachable
indicates that the sandbox environment is unable to reach the MySQL server at 10.80.2.195
. This is likely due to network restrictions in the sandbox environment.
In Dify, the sandbox service is configured to use a custom network (ssrf_proxy_network
) that is isolated and cannot access external networks directly. To allow the sandbox to connect to external services like your MySQL server, you need to adjust the network configuration.
Here are the steps to modify the network configuration:
Update the docker-compose.middleware.yaml
file:
Ensure that the sandbox
service is connected to a network that has access to external networks. You can modify the networks
section to include the default network or another network that has external access.
services:
sandbox:
...
networks:
- default
- ssrf_proxy_network
ssrf_proxy:
...
networks:
- ssrf_proxy_network
- default
networks:
ssrf_proxy_network:
driver: bridge
internal: true
default:
driver: bridge
Rebuild and redeploy the containers:
After updating the docker-compose.middleware.yaml
file, rebuild and redeploy the containers to apply the changes.
docker-compose down
docker-compose up -d --build
Test the connection: Once the containers are up and running, test the connection to the MySQL server from within the sandbox container.
docker exec -it <sandbox_container_id> /bin/sh
Inside the container, use ping
or curl
to test connectivity to the MySQL server.
ping 10.80.2.195
By ensuring that the sandbox service is connected to a network with external access, you should be able to resolve the "Network is unreachable" error and connect to your remote MySQL server [1][2].
To continue talking to Dosu, mention @dosu.
Duplicated
Self Checks
Dify version
0.8.2
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
1.First I went into the sanbox container and installed mysql pip install pymysql
2.Entering python verifies that import pymysql is OK
3.But I went to the front-end page, used the code execution module, and reported an error:
No module named 'pymysql' error: exit status 255
✔️ Expected Behavior
How to solve please give me a detailed case
❌ Actual Behavior
No module named 'pymysql' error: exit status 255