cancel
Showing results for 
Search instead for 
Did you mean: 

Python SDK Returns Null For All Queries

So I just created a sandbox account and got my API ID and KEY

 

I went to the following link and followed it's instrucitons: https://developer.authorize.net/hello_world/

 

So I installed the python SDK module with:

pip install authorizenet

Then ran the code given verbatim, changing my API ID and KEY of course

from authorizenet import apicontractsv1
from authorizenet.apicontrollers import*
from decimal import*
 
merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name ='REPLACED WITH MY ID'
merchantAuth.transactionKey ='REPLACED WITH MY KEY'
 
creditCard = apicontractsv1.creditCardType()
creditCard.cardNumber ="4111111111111111"
creditCard.expirationDate ="2020-12"
 
payment = apicontractsv1.paymentType()
payment.creditCard = creditCard
 
transactionrequest = apicontractsv1.transactionRequestType()
transactionrequest.transactionType ="authCaptureTransaction"
transactionrequest.amount = Decimal ('1.55')
transactionrequest.payment = payment
 
 
createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = merchantAuth
createtransactionrequest.refId ="MerchantID-0001"
 
createtransactionrequest.transactionRequest = transactionrequest
createtransactioncontroller = createTransactionController(createtransactionrequest)
createtransactioncontroller.execute()
 
response = createtransactioncontroller.getresponse()
 
if (response.messages.resultCode=="Ok"):
       print"Transaction ID : %s"% response.transactionResponse.transId
else:
       print"response code: %s"% response.messages.resultCode

But the error I get is:

     if (response.messages.resultCode=="Ok"):
AttributeError: 'NoneType' object has no attribute 'messages'

This happens no matter what I try to query. Like if I try to get a list of all unsettled transactions, the Library returns Null.

 

Thanks!

normana10
Member
2 ACCEPTED SOLUTIONS

Accepted Solutions

You'll definitely need to upgrade that OpenSSL version to be able to connect to our system. In case you weren't aware, PCI-DSS requirements specify that no card transactions use older TLS implementations after next summer. Our sandbox already requires TLS 1.2, and our production systems will require it in February 2018.

 

From reading that python and OpenSSL version, I'm guessing MacOS X? If so, Apple still ships this old insecure version of OpenSSL, but doesn't update it because some of their components are still linked to it, and newer versions of OpenSSL aren't API compatible. You could try upgrading the system supplied binary in /usr/bin directly, but you'd have to deal with SIP and possibly breaking other components. You're better off leaving it in place and using something like Homebrew to install a newer version (and install a newer Python too to link to the newer version).

 

If you're not on MacOS X, you'll find similar instructions elsewhere on the net. As crypto libraries evolve and weaknesses are found, every programmer who deals with internet applications will hit this same or similar situation at some point. We call out this exact thing on the readme for our Python SDK, but the "Hello World" page has you installing the SDK without necessarily seeing that.

View solution in original post

Just for future reference, I'm also on a Mac and am developing in a virtualenv. I got around the problem with this tip:

 

https://stackoverflow.com/questions/31811949/pip-install-requestssecurity-vs-pip-install-requests-di...

 

More specificially, I got the authorize.net python library to work in my code by upgrading requests with the the security argument: 

pip install requests[security]

View solution in original post

9 REPLIES 9

Hi @normana10,

 

What version of Python are you running?

Aaron
All Star

Python 2.7.10

Can you also find out what version of the SSL library (like OpenSSL) that you're using?

 

I suspect your setup doesn't support TLS 1.2, which is required for communication with our sandbox environment, but we can tell for sure with a couple of more tests.

 

For starters, check the openSSL version:

 

import ssl
ssl.OPENSSL_VERSION

 

Then actually do a test to a site that will tell you what version of TLS you can connect with:

 

import json, urllib2
print json.load(urllib2.urlopen('https://www.howsmyssl.com/a/check'))['tls_version']"

 

 

I see

 

Here's my OpenSSL Version:

OpenSSL 0.9.8zh 14 Jan 2016

 

And here's what I get from howsmyssl:

TLS 1.0

 

You'll definitely need to upgrade that OpenSSL version to be able to connect to our system. In case you weren't aware, PCI-DSS requirements specify that no card transactions use older TLS implementations after next summer. Our sandbox already requires TLS 1.2, and our production systems will require it in February 2018.

 

From reading that python and OpenSSL version, I'm guessing MacOS X? If so, Apple still ships this old insecure version of OpenSSL, but doesn't update it because some of their components are still linked to it, and newer versions of OpenSSL aren't API compatible. You could try upgrading the system supplied binary in /usr/bin directly, but you'd have to deal with SIP and possibly breaking other components. You're better off leaving it in place and using something like Homebrew to install a newer version (and install a newer Python too to link to the newer version).

 

If you're not on MacOS X, you'll find similar instructions elsewhere on the net. As crypto libraries evolve and weaknesses are found, every programmer who deals with internet applications will hit this same or similar situation at some point. We call out this exact thing on the readme for our Python SDK, but the "Hello World" page has you installing the SDK without necessarily seeing that.

Yes I'm on a mac.

 

I was able to get a newer OpenSSL installation separate from the system's.

 

It's a complete hack, but it works.

 

Thanks!!

normana10
Member

Just for future reference, I'm also on a Mac and am developing in a virtualenv. I got around the problem with this tip:

 

https://stackoverflow.com/questions/31811949/pip-install-requestssecurity-vs-pip-install-requests-di...

 

More specificially, I got the authorize.net python library to work in my code by upgrading requests with the the security argument: 

pip install requests[security]

I am facing the issue as above. I sent amount, customer profile and the invoice and while I am getting the response it shows an error:

 

 

if transaction_response is not None:

 if transaction_response.transactionResponse.transId                                           and transaction_response.transactionResponse.transId is not "0" and not       hasattr(transaction_response.transactionResponse, 'errors') == True:
 

AttributeError: 'exceptions.Exception' object has no attribute 'transactionResponse'

 

This happens only for one customer profile while others are passing through. PLEASE HELP!!

Just got the solution. When the amount that is sent to Authorize via API call has decimals, it has to be in string format. 

 

But the weird thing is that if you give an amount $291.5 or $291.0 in number format, it passes through and does not have any issues. But when the amount has decimals other than .0 and .5, you have to send the request with the amount in string format.

 

Example: 
 
  • Amount billed = 291.5 (Number format) --> Transaction Successful
  • Amount billed = 291.0 (Number format) --> Transaction Successful
  • Amount billed = 291.6 (Number format) --> Transaction Failed
  • Amount billed = 291.6 (String Format)  -->  Transaction Successful

 

I was making an API call for a particular customer profile which had $291.6 to be billed. The API call was not None but it had a string with error message "type {http://www.w3.org/2001/XMLSchema}decimal cannot be created from: 291.6". The response handling that I had, was not handling this type of error as it was so unexpected and I thought Authorize will handle the decimals. But when I changed the amount format to string it worked and the system was getting the response back from Authorize.

 

But on a serious note Authorize should handle such type of errors which does not make any sense and not the users.