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?

Updated at:

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

  1. 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 is oss-cn-hangzhou.aliyuncs.com. VPC endpoints follow the format oss-<region-id>-internal.aliyuncs.com. Make sure the endpoint's region ID matches the region where your bucket is located.

  2. Verify that DNS resolution is working on the server. Run ping against the OSS endpoint to test connectivity:

    ping shj-test.oss-cn-hangzhou.aliyuncs.com

    If ping is blocked, use nslookup to check DNS resolution directly:

    nslookup oss-cn-hangzhou.aliyuncs.com

    A 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 as 223.5.5.5.

Applicable scope

  • OSS