【问题标题】:PyCharm / IntelliJ HTTP Client variables not workingPyCharm / IntelliJ HTTP 客户端变量不起作用
【发布时间】:2020-11-02 00:05:46
【问题描述】:

我正在尝试使用内置的 HTTP 客户端。我通过

设置我的环境变量

http-client.private.env.json

{
  "dev": {
    "username": "myuser",
    "password": "mypass"
  }
}

我的rest-api.http请求:

###
POST http://localhost:5111/login
Content-Type: application/json

{
  "email": {{username}},
  "password": {{password}}
}

我是在dev环境下运行的,结果是这样的:

POST http://localhost:5111/login

HTTP/1.1 400 
content-type: text/html
content-length: 118
date: Sun, 12 Jul 2020 18:01:24 GMT
server: hypercorn-h11

<!doctype html>
<title>400 Bad Request</title>
<h1>Bad Request</h1>
Bad request syntax or unsupported method
        

Response code: 400; Time: 19ms; Content length: 118 bytes

如果我让服务器打印请求,看起来主体丢失了:

{'_files': None,
 '_form': None,
 '_send_push_promise': functools.partial(<bound method ASGIHTTPConnection._send_push_promise of <quart.asgi.ASGIHTTPConnection object at 0x7fb5ea407eb0>>, <bound method HTTPStream.app_send of <hypercorn.protocol.http_stream.HTTPStream object at 0x7fb5ea420610>>),
 'args': ImmutableMultiDict([]),
 'body': <quart.wrappers.request.Body object at 0x7fb5ea420520>,
 'body_timeout': 60,
 'headers': Headers([('Remote-Addr', '127.0.0.1'), ('Content-Type', 'application/json'), ('Content-Length', '43'), ('Host', 'localhost:5111'), ('Connection', 'Keep-Alive'), ('User-Agent', 'Apache-HttpClient/4.5.12 (Java/11.0.7)'), ('Cookie', 'QUART_AUTH=MQ.RDryRo0feBqlOBqjRPyiiUfwxlY'), ('Accept-Encoding', 'gzip,deflate')]),
 'http_version': '1.1',
 'method': 'POST',
 'path': '/do_login',
 'query_string': b'',
 'root_path': '',
 'routing_exception': None,
 'scheme': 'http',
 'scope': {'asgi': {'spec_version': '2.1', 'version': '3.0'},
           'client': ('127.0.0.1', 44320),
           'headers': [(b'content-type', b'application/json'),
                       (b'content-length', b'43'),
                       (b'host', b'localhost:5111'),
                       (b'connection', b'Keep-Alive'),
                       (b'user-agent',
                        b'Apache-HttpClient/4.5.12 (Java/11.0.7)'),
                       (b'cookie',
                        b'QUART_AUTH=MQ.RDryRo0feBqlOBqjRPyiiUfwxlY'),
                       (b'accept-encoding', b'gzip,deflate')],
           'http_version': '1.1',
           'method': 'POST',
           'path': '/do_login',
           'query_string': b'',
           'raw_path': b'/do_login',
           'root_path': '',
           'scheme': 'http',
           'server': ('127.0.0.1', 5111),
           'type': 'http'},
 'url_rule': <QuartRule '/do_login' (OPTIONS, POST) -> do_login>,
 'view_args': {}}
[2020-07-12 14:17:30,355] 127.0.0.1:44320 POST /do_login 1.1 400 118 3759

如果我改用字符串文字,它工作正常。

我该如何修复或者这是一个错误?

PyCharm 2020.1.2

【问题讨论】:

标签: json rest intellij-idea pycharm jetbrains-ide


【解决方案1】:

尝试以字符串形式提供环境变量:

{
  "email": "{{username}}",
  "password": "{{password}}"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 2022-01-19
    • 2020-09-16
    • 2019-12-11
    • 1970-01-01
    相关资源
    最近更新 更多