Unable to connect to 'index.crates.io' when running 'cargo search'

I'm having a weird issue with trying to connect to Cargo's index registry. When I try and run cargo search maturin -vv from an MSYS2 terminal (with Rust installed) to get Cargo to update its index, I get a connection error:

$ cargo search maturin -vv

    Updating crates.io index
warning: spurious network error (3 tries remaining): [56] Failure when receiving data from the peer
(CONNECT tunnel failed, response 403)
warning: spurious network error (2 tries remaining): [56] Failure when receiving data from the peer
(CONNECT tunnel failed, response 403)
warning: spurious network error (1 tries remaining): [56] Failure when receiving data from the peer
(CONNECT tunnel failed, response 403)
error: download of config.json failed

Caused by:
  failed to download from `https://index.crates.io/config.json`

Caused by:
  [56] Failure when receiving data from the peer (CONNECT tunnel failed, response 403)

When I try and curl https://index.crates.io/config.json directly, however, I am able to download the config.json file with no issues. This is a clean Rust + cargo install on MSYS2 with no environment variables or config files set, so I'm not sure what is causing the issue.

UPDATE:
Other commands I've tried, and the errors I'm getting:

$ cargo search anyhow --config –CARGO_NET_GIT_FETCH_WITH_CLI=true

error: failed to parse value from --config argument `–CARGO_NET_GIT_FETCH_WITH_CLI=true` as a dotted
 key expression

Caused by:
  TOML parse error at line 1, column 1
    |
  1 | –CARGO_NET_GIT_FETCH_WITH_CLI=true
    | ^^
  invalid key

It seems like you are using a proxy on your system which returns 403 Forbidden as error when cargo tries to connect to it.

Thanks for the quick reply! I ran curl https://index.crates.io/config.json on the same terminal from which I ran cargo search maturin -vv, so would this still apply? This is also not to mention that pip install maturin is able to download the index and crates with no issue, also from the same terminal.

What are you using for proxy?

Also CARGO_NET_GIT_FETCH_WITH_CLI=true should be set as env var, so for example CARGO_NET_GIT_FETCH_WITH_CLI=true cargo search anyhow. It only applies to git dependencies and not registry dependencies, so it wouldn't help for your problem anyway.

@bjorn3 , thanks for your reply! I don't have any proxies enabled, as far as I can tell. Within MSYS2, these are the current environment variables I have set up:

ProgramFiles(x86)=C:\Program Files (x86)
!::=::\
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
SHELL=/usr/bin/bash
NUMBER_OF_PROCESSORS=16
FPS_BROWSER_USER_PROFILE_STRING=Default
PROCESSOR_LEVEL=6
TERM_PROGRAM_VERSION=3.7.7
MINGW_PREFIX=/ucrt64
PKG_CONFIG_PATH=/ucrt64/lib/pkgconfig:/ucrt64/share/pkgconfig
USERDOMAIN_ROAMINGPROFILE=CLRC
HOSTNAME=anonymous
PROGRAMFILES=C:\Program Files
MSYSTEM=UCRT64
ChocolateyInstall=C:\ProgramData\chocolatey
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
ORIGINAL_TEMP=/c/Users/username/AppData/Local/Temp
configsetroot=C:\windows\ConfigSetRoot
MINGW_CHOST=x86_64-w64-mingw32
OS=Windows_NT
HOMEDRIVE=C:
MSYSTEM_CARCH=x86_64
USERDOMAIN=CLRC
USERDNSDOMAIN=FED.CCLRC.AC.UK
PWD=/home/wjr38212
USERPROFILE=C:\Users\username
MANPATH=/ucrt64/local/man:/ucrt64/share/man:/usr/local/man:/usr/share/man:/usr/man:/share/man
PRINTER=Microsoft Print to PDF
TZ=Europe/London
MINGW_PACKAGE_PREFIX=mingw-w64-ucrt-x86_64
ALLUSERSPROFILE=C:\ProgramData
ORIGINAL_PATH=/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/
CommonProgramW6432=C:\Program Files\Common Files
HOME=/home/username
USERNAME=username
OneDrive=C:\Users\username\OneDrive
VIRTUAL_ENV=/home/username/envs/murfey
COMSPEC=C:\windows\system32\cmd.exe
APPDATA=C:\Users\username\AppData\Roaming
SYSTEMROOT=C:\windows
LOCALAPPDATA=C:\Users\username\AppData\Local
COMPUTERNAME=anonymous
INFOPATH=/ucrt64/local/info:/ucrt64/share/info:/usr/local/info:/usr/share/info:/usr/info:/share/info
TERM=xterm-256color
LOGONSERVER=\\LOGON12
ZES_ENABLE_SYSMAN=1
ACLOCAL_PATH=/ucrt64/share/aclocal:/usr/share/aclocal
USER=CLRC+username
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\windows\system32\WindowsPowerShell\v1.0\Modules
TEMP=/tmp
MSYSTEM_CHOST=x86_64-w64-mingw32
ORIGINAL_TMP=/c/Users/username/AppData/Local/Temp
SHLVL=1
PROCESSOR_REVISION=ba02
DriverData=C:\Windows\System32\Drivers\DriverData
VIRTUAL_ENV_PROMPT=murfey
COMMONPROGRAMFILES=C:\Program Files\Common Files
LC_CTYPE=en_GB.UTF-8
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 186 Stepping 2, GenuineIntel
SESSIONNAME=Console
PS1=(murfey) \[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\[\e[1m\]#\[\e[0m\]
PKG_CONFIG_SYSTEM_LIBRARY_PATH=/ucrt64/lib
HOMEPATH=\Users\username
XDG_DATA_DIRS=/ucrt64/share/:/usr/local/share/:/usr/share/
MSYSCON=mintty.exe
TMP=/tmp
CONFIG_SITE=/etc/config.site
PATH=/home/wjr38212/envs/murfey/bin:/ucrt64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
ProgramW6432=C:\Program Files
MSYSTEM_PREFIX=/ucrt64
WINDIR=C:\windows
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
PROCESSOR_ARCHITECTURE=AMD64
PUBLIC=C:\Users\Public
PKG_CONFIG_SYSTEM_INCLUDE_PATH=/ucrt64/include
SYSTEMDRIVE=C:
OneDriveCommercial=C:\Users\username\OneDrive
OLDPWD=/home/username/projects/cargo-test
TERM_PROGRAM=mintty
ProgramData=C:\ProgramData
_=/usr/bin/env

As for other forms of potential proxies, our company does run a corporate VPN. I have tried switching that off and running cargo search again, but it still throws up the same spurious network error warning. The only other place left would be my firewall settings, and I will have to speak with the in-house IT team about that.

Maybe CARGO_HTTP_DEBUG=true CARGO_LOG=network=trace cargo search anyhow shows what proxy was used? Be aware of the following warning in the docs for this option though:

Be wary when posting logs from this output in a public location. The output may include headers with authentication tokens which you don’t want to leak! Be sure to review logs before posting them.

2 Likes

Thank you so much for showing me how to enable logging for the Cargo function!

Thanks to you, it turns out that I had set up a separate cargo config.json file in MSYS2's home directory (/c/msys64/home/username/.cargo), not the Windows one (C:\Users\username\.cargo), and it was pointing to a proxy server I had set up earlier. :man_facepalming: Deleting it allowed cargo search to work as intended.

You've resolved my issue. :smiley:

Consider marking the reply that helped you the most as the answer so it helps others too!