gpt4 book ai didi

python - 使用 Paypal 沙箱 API 时出错

转载 作者:行者123 更新时间:2023-11-28 23:03:20 25 4
gpt4 key购买 nike

我正在尝试制作 Paypal's sandbox API工作,我正在使用一个示例项目,我得到的错误是

 response was: {"responseEnvelope":{"timestamp":"2011-12-26T12:35:19.560-08:00","ack":"Success","correlationId":"ea7c82ca4d096","build":"2279004"},"payKey":"AP-53K115241G5252300","paymentExecStatus":"CREATED"}
headers must be str
Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1522, in __call__
return response(environ, start_response)
File "/base/python27_runtime/python27_lib/versions/third_party/webob-1.1.1/webob/response.py", line 939, in __call__
start_response(self.status, headerlist)
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 129, in _StartResponse
raise InvalidResponseError('headers must be str')
InvalidResponseError: headers must be str

Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 174, in Handle
result = handler(self._environ, self._StartResponse)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1524, in __call__
return self._internal_error(e)(environ, start_response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1522, in __call__
return response(environ, start_response)
File "/base/python27_runtime/python27_lib/versions/third_party/webob-1.1.1/webob/response.py", line 939, in __call__
start_response(self.status, headerlist)
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 129, in _StartResponse
raise InvalidResponseError('headers must be str')
InvalidResponseError: headers must be str

在生产中它是同样的错误:

response was: {"responseEnvelope":{"timestamp":"2011-12-26T13:18:13.932-08:00","ack":"Success","correlationId":"d84672a2d6b1e","build":"2279004"},"payKey":"AP-2GA190885R390622U","paymentExecStatus":"CREATED"}
headers must be str
Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1522, in __call__
return response(environ, start_response)
File "/base/python27_runtime/python27_lib/versions/third_party/webob-1.1.1/webob/response.py", line 939, in __call__
start_response(self.status, headerlist)
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 129, in _StartResponse
raise InvalidResponseError('headers must be str')
InvalidResponseError: headers must be str

Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 174, in Handle
result = handler(self._environ, self._StartResponse)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1524, in __call__
return self._internal_error(e)(environ, start_response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1522, in __call__
return response(environ, start_response)
File "/base/python27_runtime/python27_lib/versions/third_party/webob-1.1.1/webob/response.py", line 939, in __call__
start_response(self.status, headerlist)
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 129, in _StartResponse
raise InvalidResponseError('headers must be str')
InvalidResponseError: headers must be str

试图运行的代码是

self.raw_response = url_request( "%s%s" % ( settings.PAYPAL_ENDPOINT, "Pay" ), data=self.raw_request, headers=headers ).content() 
logging.info( "response was: %s" % self.raw_response )
self.response = json.loads( self.raw_response )

我正在尝试从 github 上的示例运行代码。这可能与我的设置有关吗?我尝试了一个以点结尾的签名和一个不以点结尾的签名,结果相同:上面的错误消息。你能推荐我应该做什么吗?

更新

问题几乎可以肯定是由于从 python 2.5 升级到 2.7,因为如果我降级,问题就会消失。我可以记录标题,它们看起来确实是字符串:

INFO     2011-12-31 08:43:03,286 paypal.py:143] headers: {'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON', 'X-PAYPAL-SECURITY-PASSWORD': '1425859477', 'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON', 'X-PAYPAL-SECURITY-SIGNATURE': 'Al6H4Bq5kp4bKF5tyfR-p2FlAbpY5JFKl54FMzHpo.QKYew5obtYPIm.', 'X-PAYPAL-SECURITY-USERID': 'niklas_1364582637_biz_api1.eddaconsult.se', 'X-PAYPAL-DEVICE-IPADDRESS': '127.0.0.1', 'X-PAYPAL-APPLICATION-ID': 'APP-80W284485P519543T'}
INFO 2011-12-31 08:43:04,909 paypal.py:57] response was: {"responseEnvelope":{"timestamp":"2011-12-31T00:43:06.083-08:00","ack":"Success","correlationId":"bf0c9db7a13cb","build":"2279004"},"payKey":"AP-25U92494YK276842W","paymentExecStatus":"CREATED"}
ERROR 2011-12-31 08:43:04,925 webapp2.py:1528] headers must be str

当我使用 tcpdump 时,日志中没有什么特别的:

$ sudo tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
18:38:31.988690 IP6 fe80::914b:d0c9:3c27:919e.52450 > ff02::c.1900: UDP, length 146
18:38:31.989603 IP ubuntu.local.49948 > resolver1.comhem.se.domain: 9999+ PTR? c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa. (90)
18:38:31.989914 ARP, Request who-has OM-DOC-1-Bu30.comhem.se tell c213-89-134-0.bredband.comhem.se, length 46
18:38:32.006004 IP resolver1.comhem.se.domain > ubuntu.local.49948: 9999 NXDomain 0/1/0 (160)
18:38:32.006401 IP ubuntu.local.57850 > resolver1.comhem.se.domain: 20237+ PTR? e.9.1.9.7.2.c.3.9.c.0.d.b.4.1.9.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa. (90)
18:38:32.017844 IP resolver1.comhem.se.domain > ubuntu.local.57850: 20237 NXDomain* 0/1/0 (125)
18:38:32.018075 IP ubuntu.local.51652 > resolver1.comhem.se.domain: 5935+ PTR? 11.245.255.83.in-addr.arpa. (44)
18:38:32.027394 IP resolver1.comhem.se.domain > ubuntu.local.51652: 5935 1/3/3 PTR resolver1.comhem.se. (186)
18:38:32.027530 IP ubuntu.local.35513 > resolver1.comhem.se.domain: 34706+ PTR? 10.0.168.192.in-addr.arpa. (43)
18:38:32.037746 IP resolver1.comhem.se.domain > ubuntu.local.35513: 34706 NXDomain 0/1/0 (120)
18:38:32.138234 IP6 fe80::219:b9ff:fe06:928e.mdns > ff02::fb.mdns: 0 PTR (QM)? 10.0.168.192.in-addr.arpa. (43)
18:38:32.138273 IP ubuntu.local.mdns > 224.0.0.251.mdns: 0 PTR (QM)? 10.0.168.192.in-addr.arpa. (43)
18:38:32.138349 IP ubuntu.local.mdns > 224.0.0.251.mdns: 0*- [0q] 1/0/0 (Cache flush) PTR ubuntu.local. (63)
18:38:32.138675 IP ubuntu.local.50349 > resolver1.comhem.se.domain: 36768+ PTR? 1.128.89.213.in-addr.arpa. (43)
18:38:32.165618 IP resolver1.comhem.se.domain > ubuntu.local.50349: 36768 1/3/3 PTR OM-DOC-1-Bu30.comhem.se. (189)
18:38:32.165826 IP ubuntu.local.39699 > resolver1.comhem.se.domain: 32574+ PTR? 0.134.89.213.in-addr.arpa. (43)
18:38:32.174200 IP resolver1.comhem.se.domain > ubuntu.local.39699: 32574 1/3/3 PTR c213-89-134-0.bredband.comhem.se. (198)
18:38:32.174493 IP ubuntu.local.58622 > resolver1.comhem.se.domain: 34645+ PTR? b.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa. (90)
18:38:32.236655 IP resolver1.comhem.se.domain > ubuntu.local.58622: 34645 NXDomain 0/1/0 (160)
18:38:32.236852 IP ubuntu.local.52609 > resolver1.comhem.se.domain: 3885+ PTR? e.8.2.9.6.0.e.f.f.f.9.b.9.1.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa. (90)
18:38:32.245937 IP resolver1.comhem.se.domain > ubuntu.local.52609: 3885 NXDomain* 0/1/0 (125)
18:38:32.246143 IP ubuntu.local.43779 > resolver1.comhem.se.domain: 20440+ PTR? 251.0.0.224.in-addr.arpa. (42)
18:38:32.257346 IP resolver1.comhem.se.domain > ubuntu.local.43779: 20440 NXDomain 0/1/0 (99)
18:38:32.357753 IP6 fe80::219:b9ff:fe06:928e.mdns > ff02::fb.mdns: 0 PTR (QM)? 251.0.0.224.in-addr.arpa. (42)
18:38:32.357798 IP ubuntu.local.mdns > 224.0.0.251.mdns: 0 PTR (QM)? 251.0.0.224.in-addr.arpa. (42)
18:38:32.474703 IP 192.168.0.11.6646 > 192.168.0.255.6646: UDP, length 170
18:38:32.475021 IP 192.168.0.11.51530 > ubuntu.local.netbios-ssn: Flags [S], seq 88766685, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
18:38:32.475035 IP ubuntu.local.netbios-ssn > 192.168.0.11.51530: Flags [R.], seq 0, ack 88766686, win 0, length 0
18:38:32.971416 IP 192.168.0.11.51530 > ubuntu.local.netbios-ssn: Flags [S], seq 88766685, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
18:38:32.971436 IP ubuntu.local.netbios-ssn > 192.168.0.11.51530: Flags [R.], seq 0, ack 1, win 0, length 0
18:38:33.358818 IP6 fe80::219:b9ff:fe06:928e.mdns > ff02::fb.mdns: 0 PTR (QM)? 251.0.0.224.in-addr.arpa. (42)
18:38:33.358856 IP ubuntu.local.mdns > 224.0.0.251.mdns: 0 PTR (QM)? 251.0.0.224.in-addr.arpa. (42)
18:38:33.471329 IP 192.168.0.11.51530 > ubuntu.local.netbios-ssn: Flags [S], seq 88766685, win 8192, options [mss 1460,nop,nop,sackOK], length 0
18:38:33.471347 IP ubuntu.local.netbios-ssn > 192.168.0.11.51530: Flags [R.], seq 0, ack 1, win 0, length 0
18:38:33.481836 IP 192.168.0.11.51377 > ubuntu.local.1900: UDP, length 97
18:38:33.481853 IP ubuntu.local > 192.168.0.11: ICMP ubuntu.local udp port 1900 unreachable, length 133
18:38:33.482624 IP 192.168.0.11.51378 > 224.0.0.251.mdns: 0 [7q] PTR (QM)? _pdl-datastream._tcp.local. PTR (QM)? _printer._tcp.local. PTR (QM)? _ipp._tcp.local. PTR (QM)? _http._tcp.local. PTR (QM)? _workstation._tcp.local. PTR (QM)? _eppc._tcp.local. PTR (QM)? _net-assistant._tcp.local. (198)
18:38:33.482773 IP ubuntu.local.mdns > 192.168.0.11.51378: 0*- [7q],,,,,, 5/0/0 PTR ubuntu [00:19:b9:06:92:8e]._workstation._tcp.local., TXT "", SRV ubuntu.local.:9 0 0, AAAA fe80::219:b9ff:fe06:928e, A 192.168.0.10 (259)
18:38:34.988668 IP6 fe80::914b:d0c9:3c27:919e.52450 > ff02::c.1900: UDP, length 146
18:38:35.360953 IP6 fe80::219:b9ff:fe06:928e.mdns > ff02::fb.mdns: 0 PTR (QM)? 251.0.0.224.in-addr.arpa. (42)
18:38:35.360996 IP ubuntu.local.mdns > 224.0.0.251.mdns: 0 PTR (QM)? 251.0.0.224.in-addr.arpa. (42)
18:38:36.751649 IP ubuntu.local.50394 > www-17-02-ash3.facebook.com.www: Flags [F.], seq 3090446013, ack 1136569104, win 130, options [nop,nop,TS val 12239647 ecr 2503075665], length 0
18:38:37.258743 IP ubuntu.local.49776 > resolver1.comhem.se.domain: 55236+ PTR? 255.0.168.192.in-addr.arpa. (44)
18:38:37.270032 IP resolver1.comhem.se.domain > ubuntu.local.49776: 55236 NXDomain 0/1/0 (121)
18:38:37.370372 IP6 fe80::219:b9ff:fe06:928e.mdns > ff02::fb.mdns: 0 PTR (QM)? 255.0.168.192.in-addr.arpa. (44)
18:38:37.370416 IP ubuntu.local.mdns > 224.0.0.251.mdns: 0 PTR (QM)? 255.0.168.192.in-addr.arpa. (44)
18:38:37.918371 IP ubuntu.local.51337 > stackoverflow.com.www: Flags [F.], seq 3843139898, ack 3903597436, win 273, options [nop,nop,TS val 12239764 ecr 81335008], length 0
18:38:37.978365 ARP, Request who-has 192.168.0.11 tell ubuntu.local, length 28
18:38:37.978650 ARP, Reply 192.168.0.11 is-at f0:bf:97:5a:59:c7 (oui Unknown), length 46
18:38:37.988729 IP6 fe80::914b:d0c9:3c27:919e.52450 > ff02::c.1900: UDP, length 146
18:38:38.347231 IP stackoverflow.com.www > ubuntu.local.51355: Flags [F.], seq 439312178, ack 401000312, win 16, options [nop,nop,TS val 81340163 ecr 12238306], length 0
18:38:38.371686 IP6 fe80::219:b9ff:fe06:928e.mdns > ff02::fb.mdns: 0 PTR (QM)? 255.0.168.192.in-addr.arpa. (44)
18:38:38.371737 IP ubuntu.local.mdns > 224.0.0.251.mdns: 0 PTR (QM)? 255.0.168.192.in-addr.arpa. (44)
18:38:38.378349 IP ubuntu.local.51355 > stackoverflow.com.www: Flags [.], ack 1, win 123, options [nop,nop,TS val 12239810 ecr 81340163], length 0
18:38:38.941011 IP ubuntu.local.50416 > www-17-02-ash3.facebook.com.www: Flags [S], seq 653211239, win 14600, options [mss 1460,sackOK,TS val 12239866 ecr 0,nop,wscale 7], length 0
18:38:39.057758 IP www-17-02-ash3.facebook.com.www > ubuntu.local.50416: Flags [S.], seq 1083765460, ack 653211240, win 4380, options [mss 1460,nop,wscale 0,nop,nop,TS val 2503201763 ecr 12239866,sackOK,eol], length 0
18:38:47.283299 IP ubuntu.local.55413 > resolver1.comhem.se.domain: 22287+ PTR? 54.242.171.69.in-addr.arpa. (44)
18:38:47.291897 IP resolver1.comhem.se.domain > ubuntu.local.55413: 22287 1/3/0 PTR www-17-02-ash3.facebook.com. (139)
18:38:47.292194 IP ubuntu.local.58277 > resolver1.comhem.se.domain: 55103+ PTR? 12.119.34.64.in-addr.arpa. (43)
18:38:47.301399 IP resolver1.comhem.se.domain > ubuntu.local.58277: 55103 1/2/0 PTR stackoverflow.com. (119)
18:38:47.989062 IP6 fe80::914b:d0c9:3c27:919e.52450 > ff02::c.1900: UDP, length 146

最佳答案

我相信您遇到了 webapp2 的错误/功能。

redirect() 不接受 unicode 它必须是 str

尝试将 main.py #91 行更改为:

  self.redirect( pay.next_url().encode('ascii') ) # go to paypal

关于python - 使用 Paypal 沙箱 API 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8634446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com