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

執行範例無法 #113

Open
q0952 opened this issue Dec 9, 2022 · 1 comment
Open

執行範例無法 #113

q0952 opened this issue Dec 9, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@q0952
Copy link

q0952 commented Dec 9, 2022

問題說明

執行範例報錯

今天五月有人提出相同問題,不過下方沒有看到其他進展,加上系統版本不同,在此重新提問,如果叨擾還望海涵

完全新手衷心感謝有這麼完整的分享,萬分感恩!!

問題重現方法
請用下列格式告訴我該如何重現問題

  1. python -m skcom.samples.ticks
  2. python -m skcom.samples.kline
  3. python -m skcom.samples.bot

輸出訊息

PS C:\CAP_API\skcom-master> python -m skcom.samples.ticks
WARNING | 目前設定檔沒有加密, 建議您加密避免帳號外流
WARNING | 執行下列指令即可加密:
WARNING |   python -m skcom.tools.cfenc
[12:10:48] INFO    | 系統公告: SKReplyLib_OnReplyMessage:Announcement callback.
[12:11:11] INFO    | 連線成功: nKind=3001, nCode=0
[12:11:13] INFO    | 連線就緒: nKind=3003, nCode=0
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\CAP_API\skcom-master\skcom\samples\ticks.py", line 56, in <module>
    asyncio.run(main())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "C:\CAP_API\skcom-master\skcom\samples\ticks.py", line 53, in main
    await qrcv.root_task()
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 162, in root_task
    await asyncio.gather(
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 242, in request
    self.request_kline()
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 338, in request_kline
    'name': fix_encoding(p_stock.bstrStockName),
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 32, in fix_encoding
    newstr = bytes(map(ord, thestr)).decode('cp950')
ValueError: bytes must be in range(0, 256)
PS C:\CAP_API\skcom-master> 
PS C:\CAP_API\skcom-master> python -m skcom.samples.kline
WARNING | 目前設定檔沒有加密, 建議您加密避免帳號外流
WARNING | 執行下列指令即可加密:
WARNING |   python -m skcom.tools.cfenc
[12:01:04] INFO    | 系統公告: SKReplyLib_OnReplyMessage:Announcement callback.
[12:01:26] INFO    | 連線成功: nKind=3001, nCode=0
[12:01:28] INFO    | 連線就緒: nKind=3003, nCode=0
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\CAP_API\skcom-master\skcom\samples\kline.py", line 44, in <module>
    asyncio.run(main())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "C:\CAP_API\skcom-master\skcom\samples\kline.py", line 41, in main
    await qrcv.root_task()
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 162, in root_task
    await asyncio.gather(
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 242, in request
    self.request_kline()
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 338, in request_kline
    'name': fix_encoding(p_stock.bstrStockName),
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 32, in fix_encoding
    newstr = bytes(map(ord, thestr)).decode('cp950')
ValueError: bytes must be in range(0, 256)
PS C:\CAP_API\skcom-master> 
PS C:\CAP_API\skcom-master> python -m skcom.samples.bot
WARNING | 目前設定檔沒有加密, 建議您加密避免帳號外流
WARNING | 執行下列指令即可加密:
WARNING |   python -m skcom.tools.cfenc
[12:12:08] INFO    | 系統公告: SKReplyLib_OnReplyMessage:Announcement callback.
[12:12:30] INFO    | 連線成功: nKind=3001, nCode=0
[12:12:32] INFO    | 連線就緒: nKind=3003, nCode=0
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\CAP_API\skcom-master\skcom\samples\bot.py", line 213, in <module>
    main()
  File "C:\CAP_API\skcom-master\skcom\samples\bot.py", line 210, in main
    StockBot().start()
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 115, in start
    asyncio.run(self.root_task())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 162, in root_task
    await asyncio.gather(
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 242, in request
    self.request_kline()
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 338, in request_kline
    'name': fix_encoding(p_stock.bstrStockName),
  File "C:\CAP_API\skcom-master\skcom\asyncrecv.py", line 32, in fix_encoding
    newstr = bytes(map(ord, thestr)).decode('cp950')
ValueError: bytes must be in range(0, 256)
PS C:\CAP_API\skcom-master> 

請務必貼純文字訊息, 而不要貼螢幕截圖, 我比較方便複製相關文字

環境資訊

  • Windows 版本: 11
  • Python 版本: 3.10.9
  • skcom 套件版本: 0.9.8 (還不會查看,但就是從零開始由pip install skcom安裝的,應該就是這個版本)
@q0952 q0952 added the bug Something isn't working label Dec 9, 2022
@JacquesBlazor
Copy link

打開 asyncrecv.py 檔案, 找到第 32 行, 即
newstr = bytes(map(ord, thestr)).decode('cp950')
這行, 在最前面加個 # 註解掉這行
移至第 34 行, # newstr = thestr
把前面的 # 移除
變成
newstr = thestr
存檔。再執行即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants