[Go SDK] Request fails when the string fields of request body json contains percent sign
See original GitHub issueHi 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:
- Created a year ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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,When I set the
Accept
header toapplication/json
, the response is as expected. For error cases, it seems like the Looker API defaults toapplication/json
for most requests but there are cases where it needs anAccept
header. I’ve tried settingContent-Type
asapplication/json
instead but that doesn’t do the trick unfortunately.There are some SDK methods that have multiple
result_formats
not justapplication/json
, for example the RunQuery method. We could inspect the API spec and if more than oneresult_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 toapplication/json
.I can make a PR to resolve this issue with this approach? What do you think?
I think @jessicasomaiya’s implementation. @jeremytchang What do you think?