projects/repobot/v2/eval_qa.jsonl

21 lignes · 5.1 Ko

Le code et les sorties des programmes sont reproduits tels qu’ils ont tourné : commentaires et sorties sont donc en chinois.

{"question": "怎么把超时完全关掉,让请求一直等下去?", "file": "advanced/timeouts.md", "keyword": "timeout=None", "reference": "传 timeout=None,可以用在单个请求上,也可以用在 Client 上。"}
{"question": "连接超时和读取超时能分别设置成不同的值吗?", "file": "advanced/timeouts.md", "keyword": "connect=60.0", "reference": "可以。用 httpx.Timeout,比如 httpx.Timeout(10.0, connect=60.0) 表示连接超时 60 秒、其他超时 10 秒,再传给 timeout 参数。"}
{"question": "怎么开启 HTTP/2?", "file": "http2.md", "keyword": "http2=True", "reference": "先安装可选依赖 pip install httpx[http2],然后创建客户端时传 http2=True,Client 和 AsyncClient 都支持。"}
{"question": "怎么知道一个响应实际用的是 HTTP/1.1 还是 HTTP/2?", "file": "http2.md", "keyword": "http_version", "reference": "看响应的 response.http_version 属性,值是 \"HTTP/1.0\"、\"HTTP/1.1\" 或 \"HTTP/2\"。开启 HTTP/2 不代表一定用 HTTP/2,还要看服务器是否支持。"}
{"question": "请求要带用户名和密码做基本认证,怎么写?", "file": "advanced/authentication.md", "keyword": "BasicAuth", "reference": "用 httpx.BasicAuth(username=..., password=...) 作为 auth 参数,可以传给单个请求,也可以传给 Client。"}
{"question": "服务器要求 Digest 认证怎么办?", "file": "advanced/authentication.md", "keyword": "DigestAuth", "reference": "用 httpx.DigestAuth(username=..., password=...) 作为 auth 参数传给请求或 Client。"}
{"question": "怎么让请求走 HTTP 代理?", "file": "advanced/proxies.md", "keyword": "proxy=", "reference": "用 proxy 参数,在创建 Client 时传入,或者在 httpx.get(..., proxy=...) 这类顶层函数里传入。"}
{"question": "想用 SOCKS 代理,需要额外安装什么?", "file": "advanced/proxies.md", "keyword": "httpx[socks]", "reference": "需要安装可选依赖:pip install httpx[socks],之后用 proxy='socks5://...' 配置。"}
{"question": "怎么关闭 SSL 证书校验?", "file": "advanced/ssl.md", "keyword": "verify=False", "reference": "传 verify=False,比如 httpx.get(url, verify=False);用 Client 时在创建客户端时传入。"}
{"question": "怎么上传一个文件?", "file": "quickstart.md", "keyword": "files=", "reference": "用 files 参数做 multipart 上传,比如 httpx.post(url, files={'upload-file': f}),f 是以二进制方式打开的文件。"}
{"question": "下载很大的文件时,怎么一块一块地读,而不是一次读进内存?", "file": "quickstart.md", "keyword": "iter_bytes", "reference": "用流式响应:with httpx.stream('GET', url) as r,然后遍历 r.iter_bytes()(文本用 iter_text,按行用 iter_lines)。"}
{"question": "响应是 404 或 500 时,怎么让它直接抛异常?", "file": "quickstart.md", "keyword": "raise_for_status", "reference": "调用 response.raise_for_status(),状态码不是 2xx 时会抛出 httpx.HTTPStatusError。"}
{"question": "异步发请求应该用哪个类?", "file": "async.md", "keyword": "AsyncClient", "reference": "用 httpx.AsyncClient,配合 async with 和 await 使用。"}
{"question": "httpx 和 requests 在处理重定向上有什么不一样?", "file": "compatibility.md", "keyword": "follow_redirects", "reference": "requests 默认跟随重定向,httpx 默认不跟随;httpx 要显式传 follow_redirects=True(单个请求或 Client 上都可以)。"}
{"question": "怎么限制连接池里最多同时有多少个连接?", "file": "advanced/resource-limits.md", "keyword": "max_connections", "reference": "给 Client 传 limits=httpx.Limits(max_connections=..., max_keepalive_connections=...)。默认最多 100 个连接、20 个 keep-alive 连接。"}
{"question": "写测试时,怎么不真的发网络请求,而是返回一个假的响应?", "file": "advanced/transports.md", "keyword": "MockTransport", "reference": "用 httpx.MockTransport(handler),handler 接收请求并返回 httpx.Response,把它作为 transport 传给 Client。"}
{"question": "怎么显示下载进度?", "file": "advanced/clients.md", "keyword": "num_bytes_downloaded", "reference": "用流式响应下载,过程中读取 response.num_bytes_downloaded 属性,比如配合 tqdm 显示进度条。"}
{"question": "想在每个请求发出之前和收到响应之后都执行一段代码,比如打日志,怎么做?", "file": "advanced/event-hooks.md", "keyword": "event_hooks", "reference": "用事件钩子:创建 Client 时传 event_hooks={'request': [函数], 'response': [函数]}。"}
{"question": "有些域名不想走代理,环境变量怎么设置?", "file": "environment_variables.md", "keyword": "NO_PROXY", "reference": "设置 NO_PROXY 环境变量,值是逗号分隔的主机名或网址列表,这些地址的请求不走代理。"}
{"question": "网页返回的中文是乱码,怎么指定解码用的字符集?", "file": "advanced/text-encodings.md", "keyword": "default_encoding", "reference": "创建 Client 时传 default_encoding 参数指定字符集(服务器没有在 Content-Type 里给出字符集时生效)。"}