pyopenapi / pyswagger

An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.
MIT License
385 stars 89 forks source link

multiple protocol https: appended request.url in client.request #109

Closed StL-Jim closed 7 years ago

StL-Jim commented 7 years ago

Not sure how to describe this issue since I've very new to using pyswagger.

When I run client.request multiple times, the first time it runs fine, each successive time an https: gets appended to the URL.

Here's a reproducible scenario and hopefully you can tell me where I'm going wrong

from pyswagger import SwaggerApp
from pyswagger.contrib.client.requests import Client
app = SwaggerApp._create_('https://esi.tech.ccp.is/latest/swagger.json')
client = Client() # No auth

market_order_operation = app.op['get_markets_region_id_orders'](
    region_id=10000002,
    type_id=34,
    order_type='all',
)

item_order = client.request(market_order_operation)

In [28]: item_order.status Out[28]: 200

This runs fine.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Now just call the client.request again and an https: is appended to the URL

client.request(market_order_operation)

/usr/local/lib/python2.7/dist-packages/pyswagger-0.8.26-py2.7.egg/pyswagger/contrib/client/requests.pyc in request(self, req_and_resp, opt) 62 ) 63 rq = self.__s.prepare_request(rq) ---> 64 rs = self.s.send(rq, stream=True, **self.send_opt) 65 66 resp.apply_with(

/usr/lib/python2.7/dist-packages/requests/sessions.pyc in send(self, request, **kwargs) 551 552 # Get the appropriate adapter to use --> 553 adapter = self.get_adapter(url=request.url) 554 555 # Start time (approximately) of the request

/usr/lib/python2.7/dist-packages/requests/sessions.pyc in get_adapter(self, url) 596 597 # Nothing matches :-/ --> 598 raise InvalidSchema("No connection adapters were found for '%s'" % url) 599 600 def close(self):

InvalidSchema: No connection adapters were found for https:https://esi.tech.ccp.is/latest/markets/10000002/orders/?type_id=34&order_type=all&page=1&datasource=tranquility'

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Now just call the client.request a 3rd time https:https: is appended to the URL

client.request(market_order_operation)

InvalidSchema Traceback (most recent call last)

in () ----> 1 client.request(market_order_operation) /usr/local/lib/python2.7/dist-packages/pyswagger-0.8.26-py2.7.egg/pyswagger/contrib/client/requests.pyc in request(self, req_and_resp, opt) 62 ) 63 rq = self.__s.prepare_request(rq) ---> 64 rs = self.__s.send(rq, stream=True, **self.__send_opt) 65 66 resp.apply_with( /usr/lib/python2.7/dist-packages/requests/sessions.pyc in send(self, request, **kwargs) 551 552 # Get the appropriate adapter to use --> 553 adapter = self.get_adapter(url=request.url) 554 555 # Start time (approximately) of the request /usr/lib/python2.7/dist-packages/requests/sessions.pyc in get_adapter(self, url) 596 597 # Nothing matches :-/ --> 598 raise InvalidSchema("No connection adapters were found for '%s'" % url) 599 600 def close(self): InvalidSchema: No connection adapters were found for https:https:https://esi.tech.ccp.is/latest/markets/10000002/orders/?type_id=34&order_type=all&page=1&datasource=tranquility' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Each time you run client.request another **https:** gets appended
mission-liao commented 7 years ago

market_order_operation is actually (pyswagger.Request, pyswagger.Response), which is only for one-time usage. So based on current design, you need to call app.op'xxxxx' again to get another pair of (pyswagger.Request, pyswagger.Response) for next request.

To make it reusable, i need to add a "prepared" flag in pyswagger.Request, and reset what cached in pyswagger.Response.

StL-Jim commented 7 years ago

Thank you for your quick response. I really appreciate it.

I can confirm that recalling:

app.op['get_markets_region_id_orders'](
    region_id=10000002,
    type_id=34,
    order_type='all',
)

And recalling

client.request(market_order_operation)

Does work. This is a nice work around and I would be nice to make it reusable

Thank you again.

mission-liao commented 7 years ago

This issue is fixed for all builtin clients and would be available in next release. You could reuse what returned from Operation.call anytime you want.

fix is included in v0.8.27.