gpt4 book ai didi

Python urllib2 http -1 错误

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:20:18 25 4
gpt4 key购买 nike

我有这段代码,它应该可以工作,但我遇到了奇怪的错误,对于其他用户来说,这段代码工作正常。

# -*- coding: utf-8 -*-

import re, sys
import urllib2
import urllib2_file


user_hash='MTggMzc6T1dZgggggzWXpWbVptggggHTXlOV1F5WWgggggggWT0%3D'
text_file = 'sveikinimas.txt'

postdata = { 'type': '40',
'description': '',
'descr': 'Pelėsiais ir kerpėm apaugus aukštai\nTrakų štai garbinga pilis\n....',
'filetype': '2',
'name': 'Su šventėmis!',
'file': {'fd': open(text_file), 'filename': text_file},
'nfo': ''
}

req = urllib2.Request('http://www.linkomanija.net/takefreak.php',postdata)
req.add_header('Cookie', 'login=' + user_hash)
print req
response = urllib2.urlopen(req)
print response
html = response.read()
f = open("out.html", "wb")
f.write(html)
f.close()

此代码适用于另一个用户,但出现奇怪的错误:

<urllib2.Request instance at 0x0387C698>
Traceback (most recent call last):
File "C:\Users\drakaz\Desktop\lm\hello.py", line 25, in <module>
response = urllib2.urlopen(req)
File "C:\Python26\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 392, in open
response = self._open(req, data)
File "C:\Python26\lib\urllib2.py", line 410, in _open
'_open', req)
File "C:\Python26\lib\urllib2.py", line 370, in _call_chain
result = func(*args)
File "C:\Users\drakaz\Desktop\lm\urllib2_file.py", line 207, in http_open
return self.do_open(httplib.HTTP, req)
File "C:\Users\drakaz\Desktop\lm\urllib2_file.py", line 298, in do_open
return self.parent.error('http', req, fp, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 436, in error
return self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 370, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 519, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error -1:

最佳答案

错误信息来自urllib2_file。我相信,这是不合适的。您可能只想评论它并尝试是否未使用该模块。

我还看到,在帖子数据中,您里面还有另一个字典。不应该这样。只要有文件的内容。读取文件并将其内容作为字符串。没有字典,没有文件名。

关于Python urllib2 http -1 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4553550/

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