Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

导入课表时报错httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol. #1

Closed
2469354913 opened this issue Mar 11, 2023 · 6 comments
Labels
good first issue Good for newcomers

Comments

@2469354913
Copy link

描述问题:

导入课表时无法正常导入报错 httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.
期望的结果

课表成功导入

环境信息

OS: Ubuntu 22.04.1 LTS
Python Version: 3.10.6
Nonebot Version: v2.0.0rc3
httpx Version: 0.23.3
已安装 nonebot_plugin_htmlrender和nonebot_plugin_apscheduler

日志
[ERROR] nonebot | Running Matcher(type='message', module=nonebot_plugin_ai_timetable) failed.
Traceback (most recent call last):
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/root/nb/.venv/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 208, in handle_async_request
raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 17, in
File "/root/nb/.venv/lib/python3.10/site-packages/nonebot/init.py", line 273, in run
get_driver().run(*args, **kwargs)
File "/root/nb/.venv/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 187, in run
uvicorn.run(
File "/root/nb/.venv/lib/python3.10/site-packages/uvicorn/main.py", line 568, in run
server.run()
File "/root/nb/.venv/lib/python3.10/site-packages/uvicorn/server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/root/nb/.venv/lib/python3.10/site-packages/nonebot/message.py", line 141, in _check_matcher
await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)

File "/root/nb/.venv/lib/python3.10/site-packages/nonebot/message.py", line 187, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "/root/nb/.venv/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 732, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "/root/nb/.venv/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 707, in simple_run
await handler(
File "/root/nb/.venv/lib/python3.10/site-packages/nonebot/dependencies/init.py", line 108, in call
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "/root/nb/.venv/lib/python3.10/site-packages/nonebot_plugin_ai_timetable/init.py", line 85, in _
res = await r.get(res_url)
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1757, in get
return await self.request(
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/lib/python3.10/contextlib.py", line 153, in exit
self.gen.throw(typ, value, traceback)
File "/root/nb/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

@maoxig
Copy link
Owner

maoxig commented Mar 11, 2023

请问userdata.json文件里有用户发送的导出的链接吗?格式例如https://cdn.cnbj1.fds.api.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html?linkToken=

@2469354913
Copy link
Author

请问userdata.json文件里有用户发送的导出的链接吗?格式例如 https://cdn.cnbj1.fds.api.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html?linkToken=

是空的

@maoxig
Copy link
Owner

maoxig commented Mar 11, 2023

请问userdata.json文件里有用户发送的导出的链接吗?格式例如 https://cdn.cnbj1.fds.api.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html?linkToken=

是空的

原因应该是获取用户发送的url后,没有监听到response.url,可能是我的正则匹配式

base_url_re = r'https://cdn\.cnbj1\.fds\.api\.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html\?linkToken=.+'

没过滤得到正确的response.url(莫非是小米id里面出现了字母?),你可以打开那个链接后打开开发者工具,然后找到network(网络)选项,刷新页面后可以看到一些请求的url,里面应该有一个类似https://i.ai.mi.com/course-multi/table?ctId=一些数字&userId=小米ID&deviceId=设备ID&sourceName=course-app-browser的请求url
J SH9Q0N1H9G2JPSTSAO3 2
你可以看看里面到底是啥

@2469354913
Copy link
Author

请问userdata.json文件里有用户发送的导出的链接吗?格式例如 https://cdn.cnbj1.fds.api.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html?linkToken=

是空的

原因应该是获取用户发送的url后,没有监听到response.url,可能是我的正则匹配式

base_url_re = r'https://cdn\.cnbj1\.fds\.api\.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html\?linkToken=.+'

没过滤得到正确的response.url(莫非是小米id里面出现了字母?),你可以打开那个链接后打开开发者工具,然后找到network(网络)选项,刷新页面后可以看到一些请求的url,里面应该有一个类似https://i.ai.mi.com/course-multi/table?ctId=一些数字&userId=小米ID&deviceId=设备ID&sourceName=course-app-browser的请求url
J SH9Q0N1H9G2JPSTSAO3 2
你可以看看里面到底是啥

谢谢,导入的问题解决了,我看了下我的userId这一项是0匹配只有1-9所以匹配不上。不过现在有个新问题就是我获取整个周的课表信息是正确的但是当获取当天课表也就是文字信息的时候,信息是错误的。我怀疑和userId为0有关,但是没有找到解决方案。

@maoxig
Copy link
Owner

maoxig commented Mar 11, 2023

请问userdata.json文件里有用户发送的导出的链接吗?格式例如 https://cdn.cnbj1.fds.api.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html?linkToken=

是空的

原因应该是获取用户发送的url后,没有监听到response.url,可能是我的正则匹配式

base_url_re = r'https://cdn\.cnbj1\.fds\.api\.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html\?linkToken=.+'

没过滤得到正确的response.url(莫非是小米id里面出现了字母?),你可以打开那个链接后打开开发者工具,然后找到network(网络)选项,刷新页面后可以看到一些请求的url,里面应该有一个类似https://i.ai.mi.com/course-multi/table?ctId=一些数字&userId=小米ID&deviceId=设备ID&sourceName=course-app-browser的请求url
J SH9Q0N1H9G2JPSTSAO3 2
你可以看看里面到底是啥

谢谢,导入的问题解决了,我看了下我的userId这一项是0匹配只有1-9所以匹配不上。不过现在有个新问题就是我获取整个周的课表信息是正确的但是当获取当天课表也就是文字信息的时候,信息是错误的。我怀疑和userId为0有关,但是没有找到解决方案。

那个小米ID为0的url是无效的,课表信息也是无效的(应该是官方测试用的),所以要过滤掉,你可以看到我这张截图里面有两项也是userId=0,按理来说应该是userId=123456 这种才是有效的。我现在推测的是可能有某一项没匹配上,例如本该是数字的部分有字母
另外,你打开这个页面后能正确显示课表吗?

@2469354913
Copy link
Author

请问userdata.json文件里有用户发送的导出的链接吗?格式例如 https://cdn.cnbj1.fds.api.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html?linkToken=

是空的

原因应该是获取用户发送的url后,没有监听到response.url,可能是我的正则匹配式

base_url_re = r'https://cdn\.cnbj1\.fds\.api\.mi-img.com/miai-fe-aischedule-wx-redirect-fe/redirect.html\?linkToken=.+'

没过滤得到正确的response.url(莫非是小米id里面出现了字母?),你可以打开那个链接后打开开发者工具,然后找到network(网络)选项,刷新页面后可以看到一些请求的url,里面应该有一个类似https://i.ai.mi.com/course-multi/table?ctId=一些数字&userId=小米ID&deviceId=设备ID&sourceName=course-app-browser的请求url
J SH9Q0N1H9G2JPSTSAO3 2
你可以看看里面到底是啥

谢谢,导入的问题解决了,我看了下我的userId这一项是0匹配只有1-9所以匹配不上。不过现在有个新问题就是我获取整个周的课表信息是正确的但是当获取当天课表也就是文字信息的时候,信息是错误的。我怀疑和userId为0有关,但是没有找到解决方案。

那个小米ID为0的url是无效的,课表信息也是无效的(应该是官方测试用的),所以要过滤掉,你可以看到我这张截图里面有两项也是userId=0,按理来说应该是userId=123456 这种才是有效的。我现在推测的是可能有某一项没匹配上,例如本该是数字的部分有字母 另外,你打开这个页面后能正确显示课表吗?

我明白了,如果没有登录就制作课表并导入的话两个id就都会是0,登录以后刷新下链接就可以了再重新导入就可以了,现在可以正常使用了,十分感谢你的帮助

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants