What do I do if the "Connect to oss failed: [Errno -2] Name or service not known" error message appears when I upload resources to OSS?
The Connect to oss failed: [Errno -2] Name or service not known error indicates that the OSS endpoint cannot be resolved. The cause is either an invalid endpoint or a DNS resolution issue on the server.
Problem description
When uploading resources to OSS, the following error appears:
Connect to oss failed: [Errno -2] Name or service not known
This error means the client cannot resolve the OSS endpoint hostname. The connection fails before it reaches OSS.
Causes
The endpoint you specified is invalid. The endpoint may contain a typo or use the wrong region ID.
The DNS server cannot resolve the OSS hostname. Network restrictions, DNS misconfiguration, or connectivity issues on the server may prevent hostname resolution.
Solutions
-
Check that the endpoint you specified is valid. For more information, see Regions and Endpoints.
Public OSS endpoints follow this format:
oss-<region-id>.aliyuncs.com. For example, the endpoint for the China (Hangzhou) region isoss-cn-hangzhou.aliyuncs.com. VPC endpoints follow the formatoss-<region-id>-internal.aliyuncs.com. Make sure the endpoint's region ID matches the region where your bucket is located. -
Verify that DNS resolution is working on the server. Run
pingagainst the OSS endpoint to test connectivity:ping shj-test.oss-cn-hangzhou.aliyuncs.comIf
pingis blocked, usenslookupto check DNS resolution directly:nslookup oss-cn-hangzhou.aliyuncs.comA successful response includes IP address records for the endpoint. If the command returns
NXDOMAIN,SERVFAIL, or no address records, DNS resolution is not working. Check the DNS server configuration on your host, or switch to a public DNS server such as223.5.5.5.
Applicable scope
OSS