Yelp / bravado

Bravado is a python client library for Swagger 2.0 services
Other
606 stars 117 forks source link

Bravado returns NoneType but a request has returned data to it #280

Open kenrestivo-stem opened 7 years ago

kenrestivo-stem commented 7 years ago

Looking at a very basic GET with bravado to a private server. We squared away the SSL issue, and bravado can access the server.

Now bravado is returning NoneType for get requests that definitely hit the server, and definitely return something:

Apr  3 23:36:30 foo 8880e03e2055[1165]: 96.90.206.57 - - [03/Apr/2017:23:36:30 +0000] "GET /api/ping HTTP/1.1" 301 184 "-" "python-requests/2.11.1" "-"
Apr  3 23:36:30 foo 8880e03e2055[1165]: 96.90.206.57 - - [03/Apr/2017:23:36:30 +0000] "GET /api/ping HTTP/1.1" 200 5 "-" "python-requests/2.11.1" "-"
Apr  3 23:36:54 foo 8880e03e2055[1165]: 96.90.206.57 - - [03/Apr/2017:23:36:54 +0000] "GET /api/version HTTP/1.1" 301 184 "-" "python-requests/2.11.1" "-"
Apr  3 23:36:54 foo 8880e03e2055[1165]: 96.90.206.57 - - [03/Apr/2017:23:36:54 +0000] "GET /api/version HTTP/1.1" 200 134 "-" "python-requests/2.11.1" "-"

But all bravado returns is NoneType:

from bravado.client import SwaggerClient
client = SwaggerClient.from_url('https://foo/api/swagger.json')
client.ping.get_ping().result() # returns nothing. useless
client.version.get_version().result() # returns nothing. useless

Does bravado/requests handle 301 redirects?

mmulich commented 7 years ago

I ran into this as well. I believe you need to define the response type information. So at a minimum, defining the response type as string will provide a response other than None.

For example (swagger definition in yaml):

  /ping:
    get:
      summary: Pings the server
      description: ''
      produces:
        - application/json
      responses:
        '200':
          description: successful operation

☝️ will result in the None value you are getting. 👇 and the following will at least give you a string value (not parsed json).

  /ping:
    get:
      summary: Pings the server
      description: ''
      produces:
        - application/json
      responses:
        '200':
          description: successful operation
          # FIXME used to get response data from bravado
          schema:
            type: string

I hope that helps