我编写了一个程序来从国家证券交易所下载文本文件。这是下载功能:
downloadNseBhav: func [Date] [
NSE_Url: to-url rejoin [
"http://nseindia.com/content/historical/EQUITIES/"
(uppercase form-date Date "%Y/%b/") "cm" Sd "bhav.csv.zip"
; format NSE Bhavcopy url
]
either error? try [
write/binary to-file rejoin ["./NSE/" Sd "bhav.csv.zip"]
read/binary NSE_Url
; download bhavcopy zip file to disk in ./NSE folder
][
append Log/text "Server made a boo boo ......NSE Bhavcopy not found^/^/"
scroll-text Log
Exit
][
append Log/text "Downloaded NSE Bhavcopy Zip^/"
scroll-text Log
]
]
尽管所需的文件存在,但我多次收到文件未找到的消息。当请求多个文件而其中一些文件未下载时,这是令人恼火的。如果我再试一次,我就会收到该文件。
我阅读了 Rebol 2 文档中的 wait
命令,发现 wait 是打开端口的默认设置。我究竟做错了什么?有没有办法让 Rebol 等待几秒钟才能从服务器获取响应?
编辑- 每天的事件都有一个文件。假设我下载了 10 天(1 月 1 日到 1 月 10 日)。然后,我在几天内收到文件,在几天内收到错误。如果我在同一日期立即再次下载,我会收到一些丢失的文件。第三个和第四个try 将获取所有剩余文件。但是,对于任何日期,每次都会随机出现文件未找到错误。
嗯,
- 正如 tomc 所说,我将超时时间增加到 10 秒。
- 按照 Graham Chiu 的建议,我还收集了失败的名单
我无法按照 Hostilfork 的建议使用 Wireshark,但我可以通过稍微更改代码来捕获错误,如下所示。
either error? err: try [ BC: read/binary NSE_Url ] ; download bhavcopy zip file to disk in ./NSE folder [ err: disarm err probe err write/append %log.txt rejoin ["NSE EQUITIES/bhavcopy not found " DateYmd "^/"] Exit ] [] ]
此后,我从2015年12月1日到2015年12月15日下载了两次。
首次尝试失败的列表 -
NSE EQUITIES/bhavcopy not found 2015-12-08
NSE EQUITIES/bhavcopy not found 2015-12-09
第二次尝试失败的列表-
NSE EQUITIES/bhavcopy not found 2015-12-01
NSE EQUITIES/bhavcopy not found 2015-12-02
所有情况下的错误消息都是相同的 -
emake object! [
code: 507
type: 'access
id: 'no-connect
arg1: "nseindia.com"
arg2: none
arg3: none
near: [BC: read/binary NSE_Url]
where: 'open-proto
]
请原谅我之前没有正确捕获错误。我是 Rebol 的新手。
不知道有什么办法解决这个问题。我有 8 mbps 的网络连接,并且工作正常。
出于好奇,我打开了 Rebol 控制台并连接了 google.co.in 这是两次同时尝试的结果-
test: read http:// google . co. in
Access Error: Cannot connect to google.co.in
Where: open-proto
Near: test: read http://google.co.in
test: read http://google.co.in
== {<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-IN"><head><meta content="text/html; charset=UTF...
因此,到目前为止,我正在遵循这两条建议。
我又学到了一件事 - 捕获错误不是这样工作的 -
either error? err: try [
write/binary to-file rejoin ["./NSE/" Sd "bhav.csv.zip"]
read/binary NSE_Url]
文件必须读入变量,否则如果实际收到文件,Rebol2 会崩溃并出现错误 - 错误:需要一个值。
最佳答案
在 R2 中,您可以使用
设置 http 超时system/schemes/http/timeout: whatever
关于rebol - 从 HTTP 读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34805827/