-
Notifications
You must be signed in to change notification settings - Fork 23
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
REST API: POST requests to Compute API fail with 411 (Length Required) #121
Comments
Hey, I have almost the same working example here:
and it works without issues. In fact, I just copied your code and filled in my parameters and it seems to be working also as I expected. So, something different in your environment and looking at your response it a bit weird, it returns HTML instead of more REST-friendly responses. So, there are possible issues:
|
Most likely this is related to the authentication so you have something off in your generated token. |
Hey! Thanks for your response :)
I'm using service account saved as JSON. This service account should have the necessary permissions, but I'll double check.
Here's my Cargo.toml:
Hmm, this exact URL is returning 404.
In the parameters of the |
Your Cargo.toml is fine.
I'm quite sure this is related to the way your app is authenticated. How did you generate that JSON file? Is there anything unusual about it?
Yes, this should return 404 since this is only the base URL for the API.
Yes, something off in instance name for example? |
Try to check using:
and compare those JSON files - one generated by gcloud tool, and another yours. |
I checked even when you don't permissions you are supposed to get something like this:
please check if you provided appropriate PROJECT_ID as well. |
Here's the initialization bit: let google_rest_client = Arc::new(
gcloud_sdk::GoogleRestApi::with_token_source(
TokenSourceType::File("./google-service-account.json".into()),
GCP_DEFAULT_SCOPES.clone(),
)
.await?,
); I assume |
This is interesting, so you're saying the same setup for the same project ID and instance names you have actually other methods working and only |
Can you elaborate how are using those configs? Are you storing them for long time and reusing? If so, please create them for each requests separately, since they contain short lived tokens. |
I tested this example with my service account and test project:
and it works. Something different with our environments or parameters. |
If we're talking about
I'm creating a new config before every request and I'm not storing them anywhere.
I will triple check everything and will try a different service account |
I think service accounts are irrelevant now - if at least one method is working. |
I've tried sending the same request from a Google Cloud instance located in the same zone/region, but it returned the same response.
They are the same as the ones I use for |
It is hard me to help here since this is not reproducible on my infrastructure. As one possible option to debug you can try to check HTTP request printing it out before it sent to Google. Just add some print inside locally cloned in google cloud sdk crate when the request is built. It may show something unexpected. One more option is to try to use some kind of HTTP to HTTPS simple proxy and check the traffic, but it maybe more complicated. |
I took another try at this. I forked this repo, added it via diff --git a/gcloud-sdk/src/rest_apis/google_rest_apis/compute_v1/apis/instances_api.rs b/gcloud-sdk/src/rest_apis/google_rest_apis/compute_v1/apis/instances_api.rs
index 989d988a2..2d4833810 100644
--- a/gcloud-sdk/src/rest_apis/google_rest_apis/compute_v1/apis/instances_api.rs
+++ b/gcloud-sdk/src/rest_apis/google_rest_apis/compute_v1/apis/instances_api.rs
@@ -7023,6 +7023,7 @@ pub async fn compute_instances_start(
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
+ local_var_req_builder = local_var_req_builder.header(reqwest::header::CONTENT_LENGTH, 0);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?; It works with the explicit I really don't know why it works on your infrastructure. |
This may be relevant: seanmonstar/reqwest#838 |
I can also confirm that you can replace the default let mut headers = reqwest::header::HeaderMap::new();
headers.insert(CONTENT_LENGTH, 0.into());
let http_client = reqwest::ClientBuilder::new()
.default_headers(headers)
.build()
.unwrap();
let google_rest_client = gcloud_sdk::GoogleRestApi::with_client_token_source(
http_client,
token_source_type,
token_scopes,
).await?; Although I'm not sure whether it will break requests with non-empty body... |
Hey, hm, interesting. Maybe this is related that I had different reqwest version when I tested it. |
The problem with this it can be 0 only when body is actually empty. And that's not true for all requests, but only for some of them. |
Same: [[package]]
name = "reqwest"
version = "0.11.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" |
I'll test it again and come back to you. Thanks for the update! |
I assume setting the body explicitly results in implicit update of |
I just tested it again, and it still works for me with no issues 🤔 You sure you don't have any proxy between your application and Google Cloud?
|
Also tested it with the latest |
Another theory, maybe this is also different in different GCP regions. Which GCP region/zone are you trying to work with? |
Which OS are you using as well? |
I'm sure I don't -- I even tried to start an instance in the same zone and send a request from there but it still didn't work
Locally macOS 13.4. For production, I deploy via Docker with |
Just tested it on Mac OS + us-central1. Works again for me :/ This is frustrating. I tested this on different laptops now, and I just update the example gcs-rest-client with just this code:
and it works without any issue. Do you a complete simple example that doesn't work for you? (obviously, don't include any sensitive info there, like service accounts etc). |
I'm trying to start a stopped/terminated compute instance:
Here's the response I get:
Stripped down:
The text was updated successfully, but these errors were encountered: