3

I want to use FedEx API for shipping in python. I installed fedex lib:

pip install fedex

but when I try to use it I got an error. Help, please.

from fedex.config import FedexConfig

CONFIG_OBJ = FedexConfig(key='<key>',
password='<pass>',
account_number='<account_no>',
meter_number='<meter_no>')

error

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from fedex.config import FedexConfig
ImportError: No module named config

the install, and upgrade

root@server:~#  pip install fedex
Requirement already satisfied (use --upgrade to upgrade): fedex in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): suds-jurko in /usr/local/lib/python2.7/dist-packages (from fedex)

root@server:~# pip install fedex --upgrade
Requirement already up-to-date: fedex in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: suds-jurko in /usr/local/lib/python2.7/dist-packages (from fedex)
Cleaning up...
  • This is probably because you ran pip as root which it advises you not to do. Try removing that package and then doing `pip install fedex --user` as a normal user. – Kredns Apr 05 '18 at 18:22
  • What happens when you do `import fedex` and `import fedex.config`. Also, what does running `python --version` in the shell output? – Mad Physicist Apr 05 '18 at 18:23
  • Kredns 1: I did but, not working yet. ........Mad Physicist : Python 2.7.6, also i got the same error just on the import line – Rafael D Portilla Apr 05 '18 at 18:36
  • 1
    Is your Python script called `fedex.py` by any chance? If so, try changing its name to something else. – Luke Woodward Apr 05 '18 at 19:11
  • I found it!!, for some reason, I have fedex, pyfedex-1.2.egg-info, and pyfedex-1.2-py2.7.egg on the /usr/local/lib/python2.7/dist-packages folder. I just remove the last 2 and work well :) – Rafael D Portilla Apr 05 '18 at 20:45
  • My issue was that I had named the script fedex.py. No idea why that was causing an error. Thanks @LukeWoodward – beetree Dec 21 '18 at 20:10
  • @beetree if your script is named `fedex.py` then that means it defines a module named `fedex`. So when you try to import something from `fedex` Python thinks you're trying to import from your module rather than the installed module. – Luke Woodward Dec 26 '18 at 19:40

3 Answers3

1

Were you able to get this package to work? While i was able to define everything in the config_obj, i keep getting a "FedexTrackRequests is not defined " error when trying to track a package via code below (with a proper tracking number entered in).

track = FedexTrackRequest(CONFIG_OBJ)
tracking_num = '############3'
track.SelectionDetails.PackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG'
track.SelectionDetails.PackageIdentifier.Value = tracking_num
track.send_request()
FlyingZebra1
  • 1,285
  • 1
  • 18
  • 28
  • 1
    Make sure to update self.SelectionDetails.CarrierCode = 'FDXG' or to the carriercode of the tracking number and also do .strip(" ") on the tracking number value to remove any white space. This resolved similar issue for me. – Jason Duncan Jul 18 '19 at 17:20
0

To fix the 'FedexTrackRequest' is not defined error, you need to import the missing class. Do this by inputting this code at the top of your file. This worked for me:

from fedex.services.track_service import FedexTrackRequest

hid
  • 1
  • 1
0

You have to import the TrackRequest from track_service

from fedex.services.track_service import FedexTrackRequest
MaHarder
  • 11
  • 6