3

I was trying to use http://www.jongsma.org/gc/scripts/ofx-ba.py to grab my bank account information from wachovia. Having no luck, I decided that I would just try to manually construct some request data using this example

So, I have this file that I want to use as the request data. Let's call it req.ofxsgml:

FXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE

<OFX>
  <SIGNONMSGSRQV1>
    <SONRQ>
      <DTCLIENT>20071015021529.000[-8:PST]
      <USERID>TheNameIuseForOnlineBanking
      <USERPASS>MySecretPassword
      <LANGUAGE>ENG
      <FI>
        <ORG>Wachovia
        <FID>4309
      </FI>
      <APPID>Money
      <APPVER>1700
    </SONRQ>
  </SIGNONMSGSRQV1>
  <BANKMSGSRQV1>
    <STMTTRNRQ>
      <TRNUID>438BD6F4-2106-4C88-8DE5-7625915A2FC0
      <STMTRQ>
        <BANKACCTFROM>
          <BANKID>061000227
          <ACCTID>101555555555
          <ACCTTYPE>CHECKING
        </BANKACCTFROM>
        <INCTRAN>
          <INCLUDE>Y
        </INCTRAN>
      </STMTRQ>
    </STMTTRNRQ>
  </BANKMSGSRQV1>
</OFX>

Then, in python, I try:

>>> import urllib2
>>> query = open('req.ofxsgml').read()
>>> request = urllib2.Request('https://pfmpw.wachovia.com/cgi-forte/fortecgi?servicename=ofx&amp;pagename=PFM',
                              query,
                              { "Content-type": "application/x-ofx",
                                "Accept": "*/*, application/x-ofx"
                              })
>>> f = urllib2.urlopen(request)

This command gives me a 500 and this traceback. I wonder what is wrong with my request.

Visiting the url with no data and no concern for headers,

>>> f = urllib2.urlopen('https://pfmpw.wachovia.com/cgi-forte/fortecgi?servicename=ofx&amp;pagename=PFM')

yields the same thing as visiting that url directly,

HTTPError: HTTP Error 403: <BODY><H1>Request not allowed</H1></BODY>.

This is pretty obvious but just an observation. Everything on the subject seems to be pretty outdated. Hoping to write a simple python ofx module to open source. Maybe there is already something developed that I have not managed to find?

EDIT - If I make a flat mapping of the above information:

d = {'ACCTID': '10555555',
 'ACCTTYPE': 'CHECKING',
 'APPID': 'Money',
 'APPVER': '1700',
 'BANKID': '061000227',
 'DTCLIENT': '20071015021529.000[-8:PST]',
 'FID': '4309',
 'INCLUDE': 'Y',
 'LANGUAGE': 'ENG',
 'ORG': 'Wachovia',
 'TRNUID': 'I18BD6F4-2006-4C88-8DE5-7625915A2FC0',
 'USERID': 'm48m40',
 'USERPASS': '12397'}

and then urlencode it and make the request with that as the data

query=urllib.urlencode(d)
request = urllib2.Request('https://pfmpw.wachovia.com/cgi-forte/fortecgi?servicename=ofx&amp;pagename=PFM',
                              query,
                              { "Content-type": "application/x-ofx",
                                "Accept": "*/*, application/x-ofx"
                              })

f = urllib2.urlopen(request)
HTTP Error 403: <BODY><H1>Request not allowed</H1></BODY>
Skylar Saveland
  • 11,116
  • 9
  • 75
  • 91
  • Perhaps it has to do with the line endings, me using Linux and getting /n where perhaps I need /r/n ... nope that's not the only problem if it was one at all. – Skylar Saveland Nov 01 '09 at 08:11

2 Answers2

2

The problem was that you were previously passing in the data from your file directly as the data parameter to the Request. The file you were reading in contains both the headers and the data that you should be sending. You needed to supply the headers and the data separately as you have now done.

HTTP error 403 means the request was correct but the server is refusing to respond to it. Have you already signed up and arranged permission to use the web service you are trying to access? If so is there some authentication that you need to do before making the request?

Tendayi Mawushe
  • 25,562
  • 6
  • 51
  • 57
  • So, urlencode only takes on level, so if I had a dict, ``data`` I would map the following data['INCLUDE']='Y' Y Doing this sort of thing led me to a ``Request not allowed`` when I tried to build the whole dict, urlencode and post to that url. That page seems like it's suggesting that the request is made with the ofxsgml http://www.ofx.net/OFXExamplesPage/OFXExamples.aspx ... I don't see how one can send structured data. – Skylar Saveland Nov 01 '09 at 12:26
0

could just be authentication? (or lack therof?)

dartdog
  • 10,432
  • 21
  • 72
  • 121