marcoceppi / python-spacetraders

A Python SpaceTraders library for interacting with the API
13 stars 2 forks source link

Unable to pass attributes to purchase_ship() #2

Closed ipaulo closed 1 year ago

ipaulo commented 1 year ago

Using the new pydantic style for json_body, I can't seem to pass attributes to purchase_ship().

from spacetraders import AuthenticatedClient

API_BASE_URL="https://api.spacetraders.io/v2"

mytoken = "SECRET"

client = AuthenticatedClient(
    base_url=API_BASE_URL,
    token=mytoken,
)

shipyard = "X1-DF55-69207D"
resp = client.fleet.purchase_ship(shipType="SHIP_PROBE", waypointSymbol=shipyard)
print(resp.content.decode())

resp = client.fleet.purchase_ship(ship_type="SHIP_PROBE", waypoint_symbol=shipyard)
print(resp.content.decode())

The API response from the first request (with shipType=) is:

{"error":{"message":"Request could not be processed due to an invalid payload.","code":422,"data":{"shipType":["The shipType field is required."],"waypointSymbol":["The waypointSymbol field is required."]}}}

The second request (with shib_type=) gives this python error:

Traceback (most recent call last):
  File "C:\code\mysp\snippet.py", line 19, in <module>
    resp = client.fleet.purchase_ship(ship_type="SHIP_PROBE", waypoint_symbol=shipyard)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\code\mysp\Lib\site-packages\spacetraders\api\fleet\purchase_ship.py", line 80, in sync_detailed
    json_body = PurchaseShipJsonBody(**json_body)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 2 validation errors for PurchaseShipJsonBody
shipType
  field required (type=value_error.missing)
waypointSymbol
  field required (type=value_error.missing)