今すぐお試しください!

製品の詳細CData ODBC Driver for FedEx を確認して、無償評価版をダウンロード:

今すぐダウンロード

PyCharm でCData ODBC Driver for FedEx を使ってみた

FedEx にODBC データソースとしてPyCharm から連携。

CData ODBC Drivers は、ODBC をサポートするあらゆる環境から利用可能です。 本記事では、PyCharm からのCData ODBC Driver for FedEx の利用を説明します。ODBC Deriver をデータソースとして設定する方法、データソースをクエリするPyCharm のベーシックな方法を含みます。

To begin, this tutorial will assume that you have already installed the CData ODBC Driver for FedEx as well as PyCharm.

Pyodbc をプロジェクトに追加

Follow the steps below to add the pyodbc module to your project.

  1. Click File -> Settings to open the project settings window.
  2. Click Project Interpreter from the Project: YourProjectName menu.
  3. To add pyodbc, click the + button and enter pyodbc.
  4. Click Install Package to install pyodbc.

FedEx への接続

You can now connect with an ODBC connection string or a DSN. See the Getting Started section in the CData driver documentation for a guide to creating a DSN on your OS.

There are five pieces of information needed in order to authenticate its actions with the FedEx service. This information is below.

  • Server: This controls the URL where the requests should be sent. Common testing options for this are: "https://gatewaybeta.fedex.com:443/xml", "https://wsbeta.fedex.com:443/xml", "https://gatewaybeta.fedex.com:443/web-service", and "https://wsbeta.fedex.com:443/web-service"
  • DeveloperKey: This is the identifier part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • Password: This is the secret part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • AccountNumber: This valid 9-digit FedEx account number is used for logging into the FedEx server.
  • MeterNumber: This value is used for submitting requests to FedEx. This value will be provided to you by FedEx after registration.
  • PrintLabelLocation: This property is required if one intends to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

The Cache Database

Many of the useful tasks available from FedEx require a lot of data. To ensure this data is easy to input and recall later, utilizes a cache database to make these requests. You must set the cache connection properties:

  • CacheProvider: The specific database you are using to cache with. For example, org.sqlite.JDBC.
  • CacheConnection: The connection string to be passed to the cache provider. For example, jdbc:sqlite:C:\users\username\documents\fedexcache.db

Below is the syntax for a DSN:

[CData FedEx Source] Driver = CData ODBC Driver for FedEx Description = My Description Server = 'https://gatewaybeta.fedex.com:443/xml' DeveloperKey = 'alsdkfjpqoewiru' Password = 'zxczxqqtyiuowkdlkn' AccountNumber = '110371337' MeterNumber = '240134349' PrintLabelLocation = 'C:\users\username\documents\mylabels' CacheProvider = 'org.sqlite.JDBC' CacheConnection = 'jdbc:sqlite:C:\users\username\documents\fedexcache.db'

FedEx へのクエリの実行

Instantiate a Cursor and use the execute method of the Cursor class to execute any SQL statement.

import pyodbc cnxn = pyodbc.connect('DRIVER={CData ODBC Driver for FedEx};Server = 'https://gatewaybeta.fedex.com:443/xml';DeveloperKey = 'alsdkfjpqoewiru';Password = 'zxczxqqtyiuowkdlkn';AccountNumber = '110371337';MeterNumber = '240134349'; PrintLabelLocation = 'C:\users\username\documents\mylabels';CacheProvider = 'org.sqlite.JDBC';CacheConnection = 'jdbc:sqlite:C:\users\username\documents\fedexcache.db';') cursor = cnxn.cursor() cursor.execute("SELECT FirstName, Phone FROM Senders WHERE SenderID = 'ab26f704-5edf-4a9f-9e4c-25'") rows = cursor.fetchall() for row in rows: print(row.FirstName, row.Phone)

After connecting to FedEx in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to FedEx data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at support@cdata.com.

 
 
ダウンロード