【问题标题】:coreapi : can not get schemacoreapi:无法获取架构
【发布时间】:2020-06-30 14:45:41
【问题描述】:

python 3.7

我有一个运行测试的 python 应用程序:

$ python -m unittest

包代码如下:

import coreapi
from coreapi import codecs

class myClient():

    myApiUrl = None

    client = None

    def __init__(self, myApiUrl, authenticationToken):

        self.myApiUrl = myApiUrl

        auth = coreapi.auth.TokenAuthentication(
            scheme='Token',
            token=authenticationToken
        )

        decoders = [
            codecs.CoreJSONCodec(),
            codecs.JSONCodec()
        ]

        self.client = coreapi.Client(auth=auth, decoders=decoders)


    def getSomething(self):
        ....at this point self.client.decoders are present....
        schema = self.client.get(self.myApiUrl)
        .......blah-blah....

这个测试运行以这个错误结束:

错误:test_doFirstTest (myclient.tests.SomeTestClass)

Traceback (most recent call last):    File "/usr/src/app/myclient/tests.py", line 82, in test_doFirstTest

     output = client.test_doFirstTest()    File "/usr/src/app/myclient/myClient.py", line 42, in getSomething

     schema = self.client.get(self.myApiUrl)    File "/opt/conda/lib/python3.7/site-packages/coreapi/client.py", line 136, in get

     return transport.transition(link, decoders, force_codec=force_codec)    File "/opt/conda/lib/python3.7/site-packages/coreapi/transports/http.py", line 380, in transition

     result = _decode_result(response, decoders, force_codec)    File "/opt/conda/lib/python3.7/site-packages/coreapi/transports/http.py", line 284, in _decode_result

     codec = utils.negotiate_decoder(decoders, content_type)    File "/opt/conda/lib/python3.7/site-packages/coreapi/utils.py", line 207, in negotiate_decoder

     raise exceptions.NoCodecAvailable(msg)  coreapi.exceptions.NoCodecAvailable: Unsupported media in Content-Type header 'text/html'

我意识到它告诉我它收到的是 text/html 而不是 json(可能是一个空字符串?),但为什么呢?我还没有做任何请求,我正在做一个获取模式对象的准备步骤。

这不是连接问题,当它根本无法连接时会给出不同的错误。

谢谢

【问题讨论】:

    标签: python json request client content-type


    【解决方案1】:

    好吧,这与 coreapi、codex、unittest、requests 或任何我能想到的东西没有任何关系。该错误的原因是一些涉及的 ​​docker 容器在启动后静默退出,因为第一个依赖的另一个 docker 容器未启动。所以这个显现恰好是无法辨认的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      • 2022-01-21
      • 2019-10-27
      • 2012-10-11
      相关资源
      最近更新 更多