使用 python 获取一些 ofx 数据

发布于 2024-08-09 03:08:55 字数 3414 浏览 2 评论 0原文

我试图使用 http://www.jongsma.org/gc/scripts /ofx-ba.py 从 wachovia 获取我的银行帐户信息。运气不好,我决定尝试使用这个示例手动构造一些请求数据

所以,我有这个文件想要用作请求数据。让我们称之为 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>

然后,在 python 中,我尝试:

>>> 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)

这个命令给我一个 500 和 这个回溯< /a>.我想知道我的要求有什么问题。

访问没有数据且不关心标头的 url,

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

会产生与访问 那个 url

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

这是非常明显的,但只是一个观察。关于这个主题的一切似乎都已经过时了。希望写一个简单的python ofx模块来开源。也许已经开发出了一些我还没有找到的东西?

编辑 - 如果我对上述信息进行平面映射:

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'}

然后对其进行 urlencode 并将其作为数据发出请求

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>

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&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&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&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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵性 2024-08-16 03:08:56

可以只是认证吗? (或者缺乏?)

could just be authentication? (or lack therof?)

说好的呢 2024-08-16 03:08:55

问题在于您之前将文件中的数据直接作为数据参数传递给 Request。您正在读取的文件包含标题和您应该发送的数据。您需要像现在一样单独提供标题和数据。

HTTP 错误 403 表示请求正确,但服务器拒绝响应。您是否已经注册并安排了使用您尝试访问的网络服务的许可?如果是这样,在发出请求之前您需要进行一些身份验证吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文