Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Order.create uses an invalid URL #78

Open
tlaredo opened this issue Jun 4, 2022 · 1 comment · Fixed by #79
Open

Order.create uses an invalid URL #78

tlaredo opened this issue Jun 4, 2022 · 1 comment · Fixed by #79

Comments

@tlaredo
Copy link

tlaredo commented Jun 4, 2022

When I try running shippo.Order.create(...), I get the following error:

shippo.error.APIConnectionError: Unexpected error communicating with Shippo. It looks like there's
probably a configuration issue locally.  If this problem persists, let
us know at [email protected].

(Network error: A CannotOverwriteExistingCassetteException was raised with error message Can't overwrite existing cassette ('tests/fixtures/cassettes/tests/rest/admin/test_regenerate_label/TestRegenerateLabel/test_label_regeneration.yaml') in your current record mode (<RecordMode.ONCE: 'once'>).
No match for the request (<Request (POST) https://api.goshippo.com/orders/>) was found.
Found 7 similar requests with 1 different matcher(s) :

1 - (<Request (POST) https://api.goshippo.com/v1/shipments/>).
Matchers succeeded : ['method', 'scheme', 'host', 'port', 'query']
Matchers failed :
path - assertion failure :
/orders/ != /v1/shipments/

2 - (<Request (POST) https://api.goshippo.com/v1/shipments/>).
Matchers succeeded : ['method', 'scheme', 'host', 'port', 'query']
Matchers failed :
path - assertion failure :
/orders/ != /v1/shipments/

3 - (<Request (POST) https://api.goshippo.com/v1/shipments/>).
Matchers succeeded : ['method', 'scheme', 'host', 'port', 'query']
Matchers failed :
path - assertion failure :
/orders/ != /v1/shipments/

4 - (<Request (POST) https://api.goshippo.com/v1/transactions/>).
Matchers succeeded : ['method', 'scheme', 'host', 'port', 'query']
Matchers failed :
path - assertion failure :
/orders/ != /v1/transactions/

5 - (<Request (POST) https://api.goshippo.com/v1/orders/>).
Matchers succeeded : ['method', 'scheme', 'host', 'port', 'query']
Matchers failed :
path - assertion failure :
/orders/ != /v1/orders/

6 - (<Request (POST) https://api.goshippo.com/v1/shipments/>).
Matchers succeeded : ['method', 'scheme', 'host', 'port', 'query']
Matchers failed :
path - assertion failure :
/orders/ != /v1/shipments/

7 - (<Request (POST) https://api.goshippo.com/v1/transactions/>).
Matchers succeeded : ['method', 'scheme', 'host', 'port', 'query']
Matchers failed :
path - assertion failure :
/orders/ != /v1/transactions/
)
> /Users/tlaredo/src/whatnot_backend/.venv/lib/python3.9/site-packages/shippo/resource.py(188)create()
-> response, api_key = requestor.request('post', url, params)

This is because the cls_url method on the Order object doesn't have the v1 prefix:

@classmethod
    def class_url(cls):
        cls_name = cls.class_name()
        return "%ss/" % (cls_name,)

Instead, it should be this:

@classmethod
    def class_url(cls):
        cls_name = cls.class_name()
        return "v1/%ss/" % (cls_name,)
@vyshakhbabji
Copy link

@tlaredo Can you please try to run this demo and let me know if you can still reproduce this issue? I tried to reproduce this issue but couldn't .

Please replace <API-KEY> with your test token

import shippo
import json
shippo.config.api_key = "<API-KEY>"
from datetime import datetime

address_from = {
    "name": "Shippo Team",
    "street1": "965 Mission St",
    "street2": "Unit 480",
    "city": "San Francisco",
    "state": "CA",
    "zip": "94103",
    "country": "US",
    "phone": "+1 555 341 9393",
}

address_to = {
    "name": "Shippo Friend",
    "street1": "1092 Indian Summer Ct",
    "city": "San Jose",
    "state": "CA",
    "zip": "95122",
    "country": "US",
    "phone": "+1 555 341 9393",
}

unit_price = 2.34
unit_weight = 25.45
unit_quantity = 2
line_item1 = {
    "title": "Demo Line Item Object",
    "sku": "demo_1234",
    "quantity": unit_quantity,
    "total_price": f"{unit_price:.2f}",
    "currency": "USD",
    "weight": f"{unit_weight:.2f}",
    "weight_unit": "lb",
    "manufacture_country": "US"
}
line_items = [line_item1]

shipping_cost = 1.23
subtotal_cost = unit_price
tax_cost = 1.065*subtotal_cost
total_cost = shipping_cost + subtotal_cost + tax_cost
my_order = {
    "order_number": f"#{datetime.now().date()}",
    "order_status": "PAID",
    "to_address": address_to,
    "from_address": address_from,
    "line_items": line_items,
    "placed_at": datetime.now().isoformat(),
    "weight": f"{10.0:.2f}",
    "weight_unit": "lb",
    "shipping_method": "ground",
    "shipping_cost": f"{shipping_cost:.2f}",
    "shipping_cost_currency": "USD",
    "subtotal_price": f"{subtotal_cost:.2f}",
    "total_price": f"{total_cost:.2f}",
    "total_tax": f"{tax_cost:.2f}",
    "currency": "USD"
}

order = shippo.Order.create(order_number=123,
                            order_status="PAID",
                            to_address=address_to,
                            from_address=address_from,
                            line_items=[line_item1],
                            placed_at=datetime.now().isoformat(),
                            weight=unit_weight*unit_quantity,
                            weight_unit="lb")
print(order)

Also, please provide me with the steps to reproduce if possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants