Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crates_io (the library) not working for me. #9040

Closed
jakobneufeld opened this issue Jan 3, 2021 · 2 comments · Fixed by #9093
Closed

crates_io (the library) not working for me. #9040

jakobneufeld opened this issue Jan 3, 2021 · 2 comments · Fixed by #9093
Labels
A-cargo-api Area: cargo-the-library API and internal code issues C-bug Category: bug

Comments

@jakobneufeld
Copy link

Problem

When I use the search function on Registry with the host "https://crates.io"
Steps

  1. A new rust project
  2. Create a registry with Registry::new()
  3. Use the search function

Possible Solution(s)

Notes
This is what my code is
use crates_io::*; fn main() { let mut crates = Registry::new(String::from("https://crates.io"), None); let mut query = crates.search("clap",10).unwrap(); }
Also, this is the panic message:
thread 'main' panicked at 'called Result::unwrap() on an Err value: failed to get a 200 OK response, got 403
headers:
HTTP/2 403

    content-length: 667

    server: nginx

    date: Sun, 03 Jan 2021 15:32:18 GMT

    strict-transport-security: max-age=31536000

    via: 1.1 vegur, 1.1 9349ae4f82564896b96f5303b030d189.cloudfront.net (CloudFront)

    x-cache: Error from cloudfront

    x-amz-cf-pop: ZRH50-C1

    x-amz-cf-id: Y5DRl7OZ_nNIvAFIOkpmCig2tYjyWmfNPCX6MmAvnIVwrA0Q5aWJrA==

body:
We require that all requests include a User-Agent header. To allow us to determine the impact your bot has on our service, we ask that your user agent actually identify your bot, and not just report the HTTP client library you're using. Including contact information will also reduce the chance that we will need to take action against your bot.

Bad:
User-Agent: reqwest/0.9.1

Better:
User-Agent: my_crawler

Best:
User-Agent: my_crawler (my_crawler.com/info)
User-Agent: my_crawler (help@my_crawler.com)

If you believe you've received this message in error, please email help@crates.io and include the request id b8cb398a-10fb-4152-99f4-5e1a74571b02.

Output of cargo version:

cargo 1.47.0 (f3c7e06 2020-08-28)
macos big sur
x64

@jakobneufeld jakobneufeld added the C-bug Category: bug label Jan 3, 2021
@jakobneufeld jakobneufeld changed the title crates_io (the library) not working for me. crates-io (the library) not working for me. Jan 3, 2021
@jakobneufeld jakobneufeld changed the title crates-io (the library) not working for me. crates_io (the library) not working for me. Jan 3, 2021
@ehuss
Copy link
Contributor

ehuss commented Jan 7, 2021

Per the error message, you need to set the user-agent. This can be done by something roughly like:

let mut handle = Easy::new();
handle.useragent("my_crawler (my_crawler.com/info)");
let mut reg = Registry::new_handle(String::from("https://crates.io"), None, handle);

I think Registry::new should probably just be removed, or extend it to take a user agent field.

@ehuss ehuss added the A-cargo-api Area: cargo-the-library API and internal code issues label Jan 7, 2021
@jakobneufeld
Copy link
Author

Thanks.
Should I close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-api Area: cargo-the-library API and internal code issues C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants