Найти - Пользователи
Полная версия: urlopen выбрасывает 404
Начало » Python для экспертов » urlopen выбрасывает 404
1
guest01
Код:

import urllib
import httplib
httplib.HTTPConnection.debuglevel = 1
data = urllib.urlopen("http://www.diveintopython.org").read()

вывод:

send: 'GET http://www.diveintopython.org HTTP/1.0\r\nHost: www.diveintopython.org\r\nUser-Agent: Python-urllib/1.17\r\n\r\n'
reply: ‘HTTP/1.1 200 OK\r\n’

А если заменить посл строчку кода на:
data = urllib.urlopen("http://www.diveintopython.org/http_web_services/debugging.html").read()

То вывод такой:

send: 'GET http://www.diveintopython.org/http_web_services/debugging.html HTTP/1.0\r\nHost: www.diveintopython.org\r\nUser-Agent: Python-urllib/1.17\r\n\r\n'
reply: ‘HTTP/1.1 404 Not Found\r\n’

В чем дело? Ведь страница существует…
j2a
Код работающий. а вывод неправильный. Должно быть:
connect: (www.diveintopython.org, 80)
send: 'GET /http_web_services/debugging.html HTTP/1.0\r\nHost: www.diveintopython.org\r\nUser-Agent: Python-urllib/1.17\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Tue, 22 May 2007 14:51:33 GMT
header: Server: Apache
header: Accept-Ranges: bytes
header: Vary: Accept-Encoding,User-Agent
header: Connection: close
header: Content-Type: text/html
Судя по версии urllib, у тебя Python-2.5. Какая платформа?
tombird
у меня работает
(на Python 2.4.4 (#71, Oct 18 2006, 08:34:43) on win32)

connect: (www.diveintopython.org, 80)
send: 'GET /http_web_services/debugging.html HTTP/1.0\r\nHost: www.diveintopython.org\r\nUser-agent: Python-urllib/1.16\r\n\r\n

reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Tue, 22 May 2007 14:48:43 GMT
header: Server: Apache
header: Accept-Ranges: bytes
header: Vary: Accept-Encoding,User-Agent
header: Connection: close
header: Content-Type: text/html
PS включи tcpdump или Wireshark , посмотри какой запрос он в реальности кидает
тогда можно будет определить где собака порылась.
guest01
*** Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32. ***

А прокси может быть виновата в этом? А то я ее тоже настраиваю (прописываю в os.environ). Сам удивляюсь…

connect: (тут моя прокси, 80)
send: 'GET http://www.diveintopython.org/soap_web_services/troubleshooting.html HTTP/1.0\r\nHost: www.diveintopython.org\r\nUser-Agent: Python-urllib/1.17\r\n\r\n'
reply: ‘HTTP/1.1 404 Not Found\r\n’
header: Date: Tue, 22 May 2007 15:01:19 GMT
header: Server: Apache/2.0.46 (Red Hat)
header: Content-Length: 327
header: Connection: close
header: Content-Type: text/html; charset=iso-8859-1
Андрей Светлов
прокси.
Если с CONNECT - надо GET делать как обычно, без http://
Если старая прокси - то GET http:://host:port/path, но в Host прописывается адрес твоей прокси
guest01
Ок. спасибо за ответы. Все оказалось проще. Надо просто порт правильный указывать, а не липу.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB