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.

RequestError: The `body`, `json` and `form` options are mutually exclusive

See original GitHub issue

hallo, thanks for this project.

i use it to translate chinese to english, a exception happen when the translate content is big.

The exception is: Error: RequestError: The body, json and form options are mutually exclusive Error: The body, json and form options are mutually exclusive

The translate content is:

我们用sureness来管理restful api认证鉴权

面对 restful api 的认证鉴权,基于 rbac (用户-角色-资源)主要关注于对 restful api 的安全保护
无特定框架依赖(本质就是过滤器处拦截判断,已有springboot,quarkus,javalin,ktor等demo)
支持动态修改权限配置(动态修改哪些api需要被认证,可以被谁访问)
支持主流http容器 servletjax-rs
支持多种认证策略, jwt, basic auth, digest auth … 可扩展自定义支持的认证方式
基于改进的字典匹配树拥有的高性能 良好的扩展接口, demo和文档
sureness的低配置,易扩展,不耦合其他框架,能使开发者对自己的项目多场景快速安全的进行保护

i guess the exception may happen in this code:

        // If request URL is greater than 2048 characters, use POST method.
        if (url.length > 2048) {
            delete data.q;
            requestOptions = [
                `${baseUrl}?${querystring.stringify(data)}`,
                {
                    method: "POST",
                    form: true,
                    body: {
                        q: text
                    }
                }
            ];
        }
```
the post method access google api may be can not use form when body is json.

Hope to help! 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kronos1390commented, Jan 5, 2021

In line 71: https://github.com/iamtraction/google-translate-api/blob/b15b464fb0a8fa4d58bc90d3d251250a8a71e907/src/index.js#L71

Just change from:

form: true,
body: {
    q: text
}

To:

form: {
    q: text
}

And then it should work

0reactions
future-minecommented, May 20, 2022
       let options = {
          method: 'POST',
          url: 'https://grp01.id.rakuten.co.jp/rms/nid/vc?l2-id=step1_pc_next_top',
          headers: {
            Host: 'grp01.id.rakuten.co.jp',
            'Cache-Control': 'max-age=0',
            'sec-ch-ua':
              '"Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'Upgrade-Insecure-Requests': '1',
            Origin: 'https://basket.step.rakuten.co.jp',
            Accept:
              'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
            'Sec-Fetch-Site': 'same-site',
            'Sec-Fetch-Mode': 'navigate',
            'Sec-Fetch-User': '?1',
            'Sec-Fetch-Dest': 'document',
            Referer: 'https://basket.step.rakuten.co.jp/',
            'Accept-Language': 'en-US,en;q=0.9',

            'Content-Type': 'application/x-www-form-urlencoded',
          },
          form: this.loginForm,
          followRedirect: false,
        };
const res = await got(options)

This is my code. Would you let me know what is wrong, please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why this "The `body`, `json` and `form` options are mutually ...
RequestError: The body , json and form options are mutually exclusive. but for some reason the main promise doesn't throw... It's a double...
Read more >
The `body`, `json` and `form` options are mutually ... - Issuehunt
How to make POST call with JSON body . Im getting RequestError: The `body`, `json` and `form` options are mutually exclusive #1222.
Read more >
Node JS request-promises POST method doesn't recognize a ...
POST data to a JSON REST API ... Set option.body to your data and json: true to encode the body as JSON. var...
Read more >
got - SurgBook
json Type: `boolean` Default: `false` *This is mutually exclusive with stream mode.* Parse response body with `JSON.parse` and set `accept` header to ...
Read more >
Renovate Bot Package Diff
+ throw new TypeError('The `body`, `json` and `form` options are mutually exclusive');. 266. + }. 267. + if (isBody &&. 268. + !is_1.default....
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