python - python,aiohttp,AssertionError:数据参数必须是字节()
问题描述
我收到标题中显示的错误。这是回溯:
2020-01-13T05:03:49.967604+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/aiohttp_debugtoolbar/middlewares.py", line 57, in toolbar_middleware
2020-01-13T05:03:49.967606+00:00 app[web.1]: return (yield from handler(request))
2020-01-13T05:03:49.967608+00:00 app[web.1]: File "/app/handlers/utils/web.py", line 139, in inner
2020-01-13T05:03:49.967610+00:00 app[web.1]: return await func(request, prepare_response, filepath, **func_kwargs)
2020-01-13T05:03:49.967612+00:00 app[web.1]: File "/app/handlers/csv2html.py", line 37, in csv2html
2020-01-13T05:03:49.967614+00:00 app[web.1]: await response.write(reader.to_html())
2020-01-13T05:03:49.967616+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/aiohttp/web_response.py", line 416, in write
2020-01-13T05:03:49.967618+00:00 app[web.1]: "data argument must be byte-ish (%r)" % type(data)
2020-01-13T05:03:49.967620+00:00 app[web.1]: AssertionError: data argument must be byte-ish (<class 'str'>)
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2020-01-13T05:03:49.967602+00:00 app[web.1]: response = await handler(request)
2020-01-13T05:03:49.967604+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/aiohttp_debugtoolbar/middlewares.py", line 57, in toolbar_middleware
2020-01-13T05:03:49.967606+00:00 app[web.1]: return (yield from handler(request))
2020-01-13T05:03:49.967608+00:00 app[web.1]: File "/app/handlers/utils/web.py", line 139, in inner
2020-01-13T05:03:49.967610+00:00 app[web.1]: return await func(request, prepare_response, filepath, **func_kwargs)
2020-01-13T05:03:49.967612+00:00 app[web.1]: File "/app/handlers/csv2html.py", line 37, in csv2html
2020-01-13T05:03:49.967614+00:00 app[web.1]: await response.write(reader.to_html())
2020-01-13T05:03:49.967616+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/aiohttp/web_response.py", line 416, in write
2020-01-13T05:03:49.967618+00:00 app[web.1]: "data argument must be byte-ish (%r)" % type(data)
2020-01-13T05:03:49.967620+00:00 app[web.1]: AssertionError: data argument must be byte-ish (<class 'str'>)
该应用程序是另一个应用程序的 api。它使用 aiohttp 并托管在 heroku 上。这个被调用的特定函数应该将 csv 转换为 html。
如果您愿意,我可以显示更多代码,但我认为没有必要。如我错了请纠正我。有人能帮忙吗?提前致谢。
解决方案
符合替换为37
_/app/handlers/csv2html.py
await response.write(reader.to_html())
await response.write(reader.to_html().encode("utf-8"))
推荐阅读
- javascript - 反应 useEffect 挂钩引用不正确的值
- java - 程序的 Java 阶乘计算不能做 0,1,2 我该如何解决这个问题
- javascript - 在 React 中将 props 传递给 this.props.children
- vue.js - vue/element ui 表单验证
- amazon-web-services - 使用 Azure AD 联合 SSO 访问 AWS 的桌面应用程序
- amazon-cloudformation - 这可能有可选的 SSM 参数吗?
- java - 如何使用版本 2 的 spring boot admin 和版本 1.5 的 spring boot?
- ios - Nativescript:添加运行脚本阶段
- javascript - 对 Flask 的 jquery Ajax 请求
- swift - 如果他们的 mod 总和在 Swift 中大于 10,如何保持更新数字