question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Go SDK] Request fails when the string fields of request body json contains percent sign

See original GitHub issue

Hi developers, Thank you for developing great SDKs.

I found that a request using Go SDK will be failed when the string field of the request body json contains % (percent sign). (I did not check other languages, but it will be happened)

For example,

{
  "some_field": "100%"
}

And I found following discussions in the looker forum. https://community.looker.com/looker-api-77/percent-sign-in-the-json-in-api-request-is-rejected-15410

I tried adding Accept and Content-Type headers explicitly as follows (at here) and such requests succeeded.

	// create new request
	req, err := http.NewRequest(method, u, bytes.NewBufferString(bodyString))
	if err != nil {
		return err
	}

        // add headers explicitly
	req.Header.Add("Accept", `application/json`)
	req.Header.Add("Content-Type", `application/json`)

	// set query params
	setQuery(req.URL, reqPars)

I would like to create PR for this problem if it is OK.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jessicasomaiyacommented, Sep 12, 2022

Hey all! Thanks @hirosassa for highlighting this issue, I’ve been having a similar problem regarding setting request headers. When querying the User method, I am getting back HTML if the user doesn’t exist. For example,

response error. status=404 Not Found. error=<!DOCTYPE html>
<html>
<head>
    <title>Looker Not Found (404)</title>
     …
     …
</html>

When I set the Accept header to application/json, the response is as expected. For error cases, it seems like the Looker API defaults to application/json for most requests but there are cases where it needs an Accept header. I’ve tried setting Content-Type as application/json instead but that doesn’t do the trick unfortunately.

There are some SDK methods that have multiple result_formats not just application/json , for example the RunQuery method. We could inspect the API spec and if more than one result_format is supported, we either add an additional argument to pass the header or we set the header as part of the request struct. If a header is not provided then we can default to application/json.

I can make a PR to resolve this issue with this approach? What do you think?

1reaction
hirosassacommented, Sep 24, 2022

I think @jessicasomaiya’s implementation. @jeremytchang What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Percent sign (%) in the json in API request is rejected
But if I use a % symbol in my query, the request is rejected, causing internal server error. Any idea why this happens?...
Read more >
Issues · looker-open-source/sdk-codegen - GitHub
One SDK to rule them all, and in the codegen bind them - Issues ... [Go SDK] Request fails when the string fields...
Read more >
sts - Amazon Web Services - Go SDK - AWS Documentation
Contains the response to a successful AssumeRole request, including temporary Amazon Web Services credentials that can be used to make Amazon Web Services ......
Read more >
Use query parameters to customize responses - Microsoft Graph
For simplicity, always include $ if using the v1 endpoint. ... be double escaped; otherwise, the request will fail due to invalid syntax....
Read more >
HTTP status and error codes for JSON | Cloud Storage
Requests that require a redirect returns status codes in the 3xx range. Error responses usually include a JSON document in the response body,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found