web-dev-qa-db-ja.com

URLはwgetで機能しますが、カールでは機能しません(aptに関連)

これは頭​​をかくような奇妙なケースです。そもそも、Sudo apt-get updateを実行したときにこのエラーが見つかりました。

Err https://packagecloud.io jessie/main AMD64 Packages                         
  Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable
Err https://packagecloud.io jessie/main i386 Packages                          
  Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable
Hit http://ppa.launchpad.net trusty/main i386 Packages                         

[...snipped...]

W: Failed to fetch https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-AMD64/Packages  Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable

W: Failed to fetch https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages  Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable

E: Some index files failed to download. They have been ignored, or old ones used instead.

注:Ubuntu 14.04 Trustyを使用していますが、Debian Jessieリポジトリからスラックをダウンロードするように設定しています。これは問題ではありません。

ブラウザでこのURL(つまり https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages )をたどると、ブラウザが完全に閲覧可能であることが示されます。したがって、aptに問題があるかどうかを確認したかったのです。したがって、curlwgetを使用しましたが、結果は異なります。

curlの場合:

$ curl -v https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages
* Hostname was NOT found in DNS cache
*   Trying 50.97.198.58...
*   Trying 2607:f0d0:2101:270::2...
* connect to 2607:f0d0:2101:270::2 port 443 failed: Network is unreachable
* Failed to connect to packagecloud.io port 443: Network is unreachable
* Closing connection 0
curl: (7) Failed to connect to packagecloud.io port 443: Network is unreachable

wgetの場合:

wget -d https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages
DEBUG output created by Wget 1.15 on linux-gnu.

URI encoding = ‘UTF-8’
--2017-07-21 18:11:10--  https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages
Resolving packagecloud.io (packagecloud.io)... 50.97.198.58, 2607:f0d0:2101:270::2
Caching packagecloud.io => 50.97.198.58 2607:f0d0:2101:270::2
Connecting to packagecloud.io (packagecloud.io)|50.97.198.58|:443... connected.
Created socket 3.
Releasing 0x00000000018412b0 (new refcount 1).
Initiating SSL handshake.
Handshake successful; connected socket 3 to SSL handle 0x00000000018415e0
certificate:
  subject: /OU=Domain Control Validated/OU=EssentialSSL/CN=packagecloud.io
  issuer:  /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
X509 certificate successfully verified and matches Host packagecloud.io

---request begin---
GET /slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages HTTP/1.1
User-Agent: Wget/1.15 (linux-gnu)
Accept: */*
Host: packagecloud.io
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response... 
---response begin---
HTTP/1.1 302 Found
Server: nginx
Date: Fri, 21 Jul 2017 12:41:17 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 0
Connection: keep-alive
Status: 302 Found
Strict-Transport-Security: max-age=31536000
Location: https://packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Cache-Control: no-cache
X-Request-Id: 571637cb-6a78-47b1-8558-45a67c428064
X-Runtime: 0.018935

---response end---
302 Found
Registered socket 3 for persistent reuse.
URI content encoding = ‘utf-8’
Location: https://packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185 [following]
] done.
URI content encoding = None
--2017-07-21 18:11:11--  https://packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185
Resolving packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com (packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com)... 52.219.20.25, 2600:1fa0:c040:80:36e7:ec1c::
Caching packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com => 52.219.20.25 2600:1fa0:c040:80:36e7:ec1c::
Connecting to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com (packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com)|52.219.20.25|:443... connected.
Created socket 4.
Releasing 0x000000000185a150 (new refcount 1).
Initiating SSL handshake.
Handshake successful; connected socket 4 to SSL handle 0x0000000001860bc0
certificate:
  subject: /C=US/ST=Washington/L=Seattle/O=Amazon.com Inc./CN=*.s3-us-west-1.amazonaws.com
  issuer:  /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Baltimore CA-2 G2
X509 certificate successfully verified and matches Host packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com

---request begin---
GET /925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185 HTTP/1.1
User-Agent: Wget/1.15 (linux-gnu)
Accept: */*
Host: packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response... 
---response begin---
HTTP/1.1 200 OK
x-amz-id-2: cDzrsyunzEU7POUHrPqzqAV+oPLWkeRrMPgDQeKATtgenMpv2EUbCQjy+88AKQ6rp8FTO2shkv0=
x-amz-request-id: 76F0FF5E248DAFDE
Date: Fri, 21 Jul 2017 12:41:19 GMT
Last-Modified: Thu, 08 Jun 2017 00:13:11 GMT
ETag: "857ccd845e08a3963199ffbb587a0f4f"
Cache-Control: max-age=31536000
Accept-Ranges: bytes
Content-Type: text/plain
Content-Length: 20053
Server: AmazonS3

---response end---
200 OK
Disabling further reuse of socket 3.
Closed 3/SSL 0x00000000018415e0
Registered socket 4 for persistent reuse.
Length: 20053 (20K) [text/plain]
Saving to: ‘Packages’

100%[====================================================================================================================================================================>] 20,053      46.6KB/s   in 0.4s   

2017-07-21 18:11:12 (46.6 KB/s) - ‘Packages’ saved [20053/20053]

基本的に、URLはwgetとブラウザを介して機能するようですが、apt-getまたはcurlを介しては機能しません。

私はプロキシをインストールしていませんし、最近ネットワーク関連の設定をいじっていません。ただし、この問題は過去1か月以上で発生しているため、これをデバッグ/修正しようとする可能性のあることを聞きたいと思います。

1
Jay Bosamiya

HTTP 302ステータスコードに注意してください。これはリダイレクトです。つまり、提供されたURLは別のURLにマップされます。デフォルトでは、wgetはリダイレクトに従いますが、curlはリダイレクトしません。通常、ブラウザはデフォルトでリダイレクトに従います。 curlがリダイレクトに従うようにするには、オプション-L or --locationを使用します。

マニュアルページから引用すると、

-L、-場所
(HTTP)要求されたページが別の場所(Location:ヘッダーと3XX応答コードで示される)に移動したことをサーバーが報告した場合、このオプションはcurlが新しい場所で要求をやり直します。

残念ながら、Ubuntuの専門家ではないため、apt-getの部分を手伝うことはできません。 考えてみて、更新サイトの場所を

packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185

の代わりに

packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages

お役に立てれば!

3
vikarjramun