karrioapi / karrio

Programmable Shipping API (self-hosted)
https://karrio.io
Apache License 2.0
497 stars 93 forks source link

Fedex Tracking having issue with estimated delivery date format #659

Closed ChrisNolan closed 1 month ago

ChrisNolan commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Add a tracker for fedex tracking number 274685452994

Expected behavior A tracker is added with the details of the delivery

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

I believe this is similar to Issue #654 but this time for the estimated delivery date. This line in 'modules/connectors/fedex/kario/providers/fedex/tracking.py'

        estimated_delivery=lib.fdate(estimated_delivery, "%Y-%m-%dT%H:%M:%S"),

Throws a ""code":"SHIPPING_SDK_INTERNAL_ERROR","message":"unconverted data remains: -05:00"}"

As the field has a timezone, and the format to fdate doesn't.

I believe a valid fix would be: estimated_delivery=lib.fdate(estimated_delivery, try_formats=DATETIME_FORMATS),

Here is the full log

DEBUG serializable.py 21 {'includeDetailedScans': True, 'trackingInfo': [{'trackingNumberInfo': {'trackingNumber': '274685452994'}}]}
DEBUG helpers.py 264 sending request (f683dc1f-fc0e-4766-9321-0c17540cceba)...
INFO helpers.py 201 Request URL:: https://apis.fedex.com/oauth/token
DEBUG helpers.py 264 sending request (abaf0c9e-2eb5-4e99-9147-d11a945e14ad)...
INFO helpers.py 201 Request URL:: https://apis.fedex.com/track/v1/trackingnumbers
DEBUG serializable.py 36 {"transactionId":"4e3f98a8-4096-4516-99f7-10e0831628d0","output":{"completeTrackResults":[{"trackingNumber":"274685452994","trackResults":[{"trackingNumberInfo":{"trackingNumber":"274685452994","trackingNumberUniqueId":"12027~274685452994~FDEG","carrierCode":"FDXG"},"additionalTrackingInfo":{"nickname":"","packageIdentifiers":[{"type":"CUSTOMER_REFERENCE","values":["I660889"],"trackingNumberUniqueId":"","carrierCode":""}],"hasAssociatedShipments":false},"shipperInformation":{"contact":{},"address":{"city":"Chattanooga","stateOrProvinceCode":"TN","countryCode":"US","residential":false,"countryName":"United States"}},"recipientInformation":{"contact":{},"address":{"city":"NORTH MANKATO","stateOrProvinceCode":"MN","countryCode":"US","residential":false,"countryName":"United States"}},"latestStatusDetail":{"code":"OC","derivedCode":"OC","statusByLocale":"Label created","description":"Shipment information sent to FedEx","scanLocation":{"residential":false},"ancillaryDetails":[{"reason":"IN001","reasonDescription":"Please check back later for shipment status or subscribe for e-mail notifications","action":"","actionDescription":""}]},"availableImages":[],"packageDetails":{"packagingDescription":{"type":"YOUR_PACKAGING","description":"Package"},"physicalPackagingType":"PACKAGE","sequenceNumber":"1","count":"1","weightAndDimensions":{"weight":[{"value":"22.2","unit":"LB"},{"value":"10.07","unit":"KG"}]},"packageContent":[]},"shipmentDetails":{"possessionStatus":false},"scanEvents":[{"date":"2024-05-15T08:16:00-04:00","eventType":"OC","eventDescription":"Shipment information sent to FedEx","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"postalCode":"37404","countryCode":"US","residential":false,"countryName":"United States"},"locationType":"CUSTOMER","derivedStatusCode":"IN","derivedStatus":"Label created"}],"availableNotifications":["ON_DELIVERY","ON_EXCEPTION","ON_ESTIMATED_DELIVERY","ON_TENDER"],"deliveryDetails":{"deliveryAttempts":"0","deliveryOptionEligibilityDetails":[{"option":"INDIRECT_SIGNATURE_RELEASE","eligibility":"INELIGIBLE"},{"option":"REDIRECT_TO_HOLD_AT_LOCATION","eligibility":"INELIGIBLE"},{"option":"REROUTE","eligibility":"INELIGIBLE"},{"option":"RESCHEDULE","eligibility":"INELIGIBLE"},{"option":"RETURN_TO_SHIPPER","eligibility":"INELIGIBLE"},{"option":"DISPUTE_DELIVERY","eligibility":"POSSIBLY_ELIGIBLE"},{"option":"SUPPLEMENT_ADDRESS","eligibility":"INELIGIBLE"}],"destinationServiceArea":"OC"},"lastUpdatedDestinationAddress":{"city":"MANKATO","stateOrProvinceCode":"MN","countryCode":"US","residential":false,"countryName":"United States"},"serviceCommitMessage":{"message":"We'll add a delivery date as soon as we get your package.","type":"SHIPMENT_LABEL_CREATED"},"serviceDetail":{"type":"FEDEX_GROUND","description":"FedEx Ground","shortDescription":"FG"},"standardTransitTimeWindow":{"window":{}},"estimatedDeliveryTimeWindow":{"window":{}},"goodsClassificationCode":"","returnDetail":{}},{"trackingNumberInfo":{"trackingNumber":"274685452994","trackingNumberUniqueId":"12028~274685452994~FDEG","carrierCode":"FDXG"},"additionalTrackingInfo":{"nickname":"","packageIdentifiers":[{"type":"CUSTOMER_REFERENCE","values":["I660889"],"trackingNumberUniqueId":"","carrierCode":""}],"hasAssociatedShipments":false},"shipperInformation":{"address":{"city":"MANKATO","stateOrProvinceCode":"MN","countryCode":"US","residential":false,"countryName":"United States"}},"recipientInformation":{"address":{"city":"NORTH MANKATO","stateOrProvinceCode":"MN","countryCode":"US","residential":false,"countryName":"United States"}},"latestStatusDetail":{"code":"OD","derivedCode":"OD","statusByLocale":"Out for delivery","description":"On FedEx vehicle for delivery","scanLocation":{"city":"MANKATO","stateOrProvinceCode":"MN","countryCode":"US","residential":false,"countryName":"United States"}},"dateAndTimes":[{"type":"COMMITMENT","dateTime":"2024-08-28T00:00:00-06:00"},{"type":"ACTUAL_PICKUP","dateTime":"2024-08-26T00:00:00-06:00"},{"type":"SHIP","dateTime":"2024-08-26T00:00:00-06:00"},{"type":"ACTUAL_TENDER","dateTime":"2024-08-26T00:00:00-06:00"},{"type":"ESTIMATED_DELIVERY","dateTime":"2024-08-28T00:00:00-06:00"}],"availableImages":[],"packageDetails":{"packagingDescription":{"type":"YOUR_PACKAGING","description":"Package"},"physicalPackagingType":"PACKAGE","sequenceNumber":"1","count":"1","weightAndDimensions":{"weight":[{"value":"22.2","unit":"LB"},{"value":"10.07","unit":"KG"}],"dimensions":[{"length":14,"width":12,"height":10,"units":"IN"},{"length":35,"width":30,"height":25,"units":"CM"}]},"packageContent":[]},"shipmentDetails":{"possessionStatus":true},"scanEvents":[{"date":"2024-08-28T04:44:00-05:00","eventType":"OD","eventDescription":"On FedEx vehicle for delivery","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"MANKATO","stateOrProvinceCode":"MN","postalCode":"56001","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0560","locationType":"VEHICLE","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-28T04:32:00-05:00","eventType":"AR","eventDescription":"At local FedEx facility","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"MANKATO","stateOrProvinceCode":"MN","postalCode":"56001","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0560","locationType":"DESTINATION_FEDEX_FACILITY","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-28T00:39:37-05:00","eventType":"DP","eventDescription":"Departed FedEx location","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"SAINT PAUL","stateOrProvinceCode":"MN","postalCode":"55115","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0552","locationType":"FEDEX_FACILITY","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-27T21:29:00-05:00","eventType":"AR","eventDescription":"Arrived at FedEx location","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"SAINT PAUL","stateOrProvinceCode":"MN","postalCode":"55115","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0552","locationType":"FEDEX_FACILITY","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-27T02:52:54-05:00","eventType":"AO","eventDescription":"Shipment arriving On-Time","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"MURFREESBORO","stateOrProvinceCode":"TN","postalCode":"37127","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0377","locationType":"FEDEX_FACILITY","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-27T02:52:08-05:00","eventType":"DP","eventDescription":"Departed FedEx location","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"MURFREESBORO","stateOrProvinceCode":"TN","postalCode":"37127","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0377","locationType":"FEDEX_FACILITY","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-27T00:41:00-05:00","eventType":"AR","eventDescription":"Arrived at FedEx location","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"MURFREESBORO","stateOrProvinceCode":"TN","postalCode":"37127","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0377","locationType":"FEDEX_FACILITY","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-26T20:36:05-04:00","eventType":"DY","eventDescription":"Delay","exceptionCode":"A52","exceptionDescription":"Package delayed","scanLocation":{"streetLines":[""],"city":"CHATTANOOGA","stateOrProvinceCode":"TN","postalCode":"37410","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0373","locationType":"DESTINATION_FEDEX_FACILITY","derivedStatusCode":"DY","derivedStatus":"Delay","delayDetail":{"type":"GENERAL"}},{"date":"2024-08-26T20:34:00-04:00","eventType":"AR","eventDescription":"Arrived at FedEx location","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"CHATTANOOGA","stateOrProvinceCode":"TN","postalCode":"37410","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0373","locationType":"FEDEX_FACILITY","derivedStatusCode":"IT","derivedStatus":"In transit"},{"date":"2024-08-26T12:23:00-04:00","eventType":"PU","eventDescription":"Picked up","exceptionCode":"","exceptionDescription":"","scanLocation":{"streetLines":[""],"city":"CHATTANOOGA","stateOrProvinceCode":"TN","postalCode":"37410","countryCode":"US","residential":false,"countryName":"United States"},"locationId":"0373","locationType":"PICKUP_LOCATION","derivedStatusCode":"PU","derivedStatus":"Picked up"}],"availableNotifications":["ON_DELIVERY","ON_EXCEPTION","ON_ESTIMATED_DELIVERY"],"deliveryDetails":{"deliveryAttempts":"0","deliveryOptionEligibilityDetails":[{"option":"INDIRECT_SIGNATURE_RELEASE","eligibility":"INELIGIBLE"},{"option":"REDIRECT_TO_HOLD_AT_LOCATION","eligibility":"POSSIBLY_ELIGIBLE"},{"option":"REROUTE","eligibility":"INELIGIBLE"},{"option":"RESCHEDULE","eligibility":"INELIGIBLE"},{"option":"RETURN_TO_SHIPPER","eligibility":"POSSIBLY_ELIGIBLE"},{"option":"DISPUTE_DELIVERY","eligibility":"POSSIBLY_ELIGIBLE"},{"option":"SUPPLEMENT_ADDRESS","eligibility":"INELIGIBLE"}]},"originLocation":{"locationContactAndAddress":{"address":{"city":"CHATTANOOGA","stateOrProvinceCode":"TN","countryCode":"US","residential":false,"countryName":"United States"}}},"lastUpdatedDestinationAddress":{"city":"MANKATO","stateOrProvinceCode":"MN","countryCode":"US","residential":false,"countryName":"United States"},"serviceDetail":{"type":"FEDEX_GROUND","description":"FedEx Ground","shortDescription":"FG"},"standardTransitTimeWindow":{"window":{"ends":"2024-08-28T00:00:00-06:00"}},"estimatedDeliveryTimeWindow":{"window":{"begins":"2024-08-28T08:45:00-05:00","ends":"2024-08-28T10:45:00-05:00"},"type":"PROJECTED"},"goodsClassificationCode":"","returnDetail":{}}]}]}}
ERROR interface.py 68 unconverted data remains: -05:00
Traceback (most recent call last):
  File "/karrio/venv/lib/python3.11/site-packages/karrio/api/interface.py", line 66, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/api/interface.py", line 444, in deserialize
    return gateway.mapper.parse_tracking_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/mappers/fedex/mapper.py", line 55, in parse_tracking_response
    return provider.parse_tracking_response(response, self.settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/providers/fedex/tracking.py", line 20, in parse_tracking_response
    details = [
              ^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/providers/fedex/tracking.py", line 21, in <listcomp>
    _extract_details(result, settings)
  File "/karrio/venv/lib/python3.11/site-packages/karrio/providers/fedex/tracking.py", line 133, in _extract_details
    estimated_delivery=lib.fdate(estimated_delivery, "%Y-%m-%dT%H:%M:%S"),
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/lib.py", line 231, in fdate
    return utils.DF.fdate(
           ^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/core/utils/datetime.py", line 39, in fdate
    date = DATEFORMAT.date(
           ^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/core/utils/datetime.py", line 31, in date
    return datetime.strptime(str(date_value), current_format)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/_strptime.py", line 567, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/_strptime.py", line 352, in _strptime
    raise ValueError("unconverted data remains: %s" %
ValueError: unconverted data remains: -05:00
ERROR abstract.py 199 [Message(carrier_name='fedex', carrier_id='fedex-ca-tracking', message='unconverted data remains: -05:00', code='SHIPPING_SDK_INTERNAL_ERROR', details=None)]
Traceback (most recent call last):
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/serializers/abstract.py", line 196, in create
    instance = super().create(payload, context=self.__context)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/manager/serializers/tracking.py", line 57, in create
    response = Shipments.track(
               ^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/core/gateway.py", line 353, in track
    raise exceptions.APIException(
karrio.server.core.exceptions.APIException: [Message(carrier_name='fedex', carrier_id='fedex-ca-tracking', message='unconverted data remains: -05:00', code='SHIPPING_SDK_INTERNAL_ERROR', details=None)]
ERROR exceptions.py 49 [Message(carrier_name='fedex', carrier_id='fedex-ca-tracking', message='unconverted data remains: -05:00', code='SHIPPING_SDK_INTERNAL_ERROR', details=None)]
Traceback (most recent call last):
  File "/karrio/venv/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/manager/views/trackers.py", line 152, in post
    .save(carrier_filter=carrier_filter, pending_pickup=pending_pickup)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/serializers/abstract.py", line 46, in save
    self._instance = self._serializer.save(**kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/rest_framework/serializers.py", line 208, in save
    self.instance = self.create(validated_data)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/serializers/abstract.py", line 200, in create
    raise e
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/serializers/abstract.py", line 196, in create
    instance = super().create(payload, context=self.__context)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/manager/serializers/tracking.py", line 57, in create
    response = Shipments.track(
               ^^^^^^^^^^^^^^^^
  File "/karrio/venv/lib/python3.11/site-packages/karrio/server/core/gateway.py", line 353, in track
    raise exceptions.APIException(
karrio.server.core.exceptions.APIException: [Message(carrier_name='fedex', carrier_id='fedex-ca-tracking', message='unconverted data remains: -05:00', code='SHIPPING_SDK_INTERNAL_ERROR', details=None)]
ChrisNolan commented 1 month ago

So, I put that code in and I believe it solved the error. I'll include it in a PR soon.

For the weirdness of the 'edge case'... I think what happened was we generated the shipping label for the customer and emailed it to them in May. They didn't actually put it on a box and give it to fedex until a couple of days ago... this confused fedex but they managed to work it through... but the tracking number is duplicated in their system....

I had asked internally if this could be an issue a couple weeks ago and they said no it has never been a problem... I believe the label should only be valid for a couple of weeks and we should give them a new label... but.... we'll see.