captin411 / ofxclient

Bank transaction downloader and python OFX client libraries
MIT License
261 stars 89 forks source link

Cannot download Amex: forbidden #68

Closed philipsd6 closed 5 years ago

philipsd6 commented 5 years ago

I was able to connect using aqbanking in GnuCash, but using the same settings in ofxclient, I receive this:

DEBUG:root:---- response ----
DEBUG:root:{'fp': None, 'debuglevel': 0, '_method': 'POST', 'headers': <http.client.HTTPMessage object at 0x7f3889dc2278>, 'msg': <http.client.HTTPMessage object at 0x7f3889dc2278>, 'version': 11, 'status': 403, 'reason': 'Forbidden', 'chunked': False, 'chunk_left': 'UNKNOWN', 'length': 0, 'will_close': True, 'code': 403}
DEBUG:root:Forbidden

I enabled OFX logging in GnuCash and verified that the SIGNONMSGSRQV1 call sent is the same, including the client args.

Here's my full test case:

In [1]: import logging                                                                                                                 
In [2]: logging.basicConfig(level=logging.DEBUG)                                                                                       
In [3]: u = 'myusername'
In [4]: p = 'mypassword'
In [5]: from ofxclient import Institution
In [6]: inst = Institution(
   ...:     id          = '3101',
   ...:     org         = 'AMEX',
   ...:     url         = 'https://online.americanexpress.com/myca/ofxdl/desktop/desktopDownload.do?request_type=nl_ofxdownload',
   ...:     username    = u,
   ...:     password    = p,
   ...:     client_args = {'ofx_version': '102',
   ...:                    'app_version': '1400'}  # Quicken Windows 2005
   ...: )
In [7]: inst.authenticate()                                                                                                           
DEBUG:root:posting data to https://online.americanexpress.com/myca/ofxdl/desktop/desktopDownload.do?request_type=nl_ofxdownload        
DEBUG:root:---- request ----                                                                                                           
DEBUG:root:OFXHEADER:100                                                                                                               
DATA:OFXSGML                                                                                                                           
VERSION:102
SECURITY:NONE
ENCODING:USASCII                                                                                                                       
CHARSET:1252                                                                                                                           
COMPRESSION:NONE                                                                                                                       
OLDFILEUID:NONE                                                                                                                        
NEWFILEUID:0cb38c8021284967b4b7adca121d879b                                                                                            

<OFX>                                                                                                                                  
<SIGNONMSGSRQV1>                                                                                                                       
<SONRQ>                                                                                                                                
<DTCLIENT>20190423124337                                                                                                               
<USERID>myusername                                                                                                                 
<USERPASS>mypassword                                                                                                                     
<LANGUAGE>ENG                                                                                                                          
<FI>                                                                                                                                   
<ORG>AMEX
<FID>3101
</FI>
<APPID>QWIN
<APPVER>1400

</SONRQ>
</SIGNONMSGSRQV1>
</OFX>
DEBUG:root:---- response ----
DEBUG:root:{'fp': None, 'debuglevel': 0, '_method': 'POST', 'headers': <http.client.HTTPMessage object at 0x7f3889dc2278>, 'msg': <http
.client.HTTPMessage object at 0x7f3889dc2278>, 'version': 11, 'status': 403, 'reason': 'Forbidden', 'chunked': False, 'chunk_left': 'UN
KNOWN', 'length': 0, 'will_close': True, 'code': 403}
DEBUG:root:Forbidden
philipsd6 commented 5 years ago

Just to be clear, the same error occurs without client_args but those are the args that worked with GnuCash/aqbanking. This is the canonical example for this project, so... it really should work!

philipsd6 commented 5 years ago

I dunno what changed, but now it's working fine.