Import error with w3lib.encoding (from requests-html)

未关闭
#657 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, python
领域
compilers

调研方向

Reproduce the compilation with rqhtstest.py and the shown requests_html.py and w3lib/encoding.py imports, then inspect how Transcrypt resolves re.translate and generated files in target. Confirm the import-resolution behavior and make the failing example compile without reporting existing generated modules as missing.

由索引模型根据 Issue 内容生成。

描述

IS: bug? IS: limitation

This may be related to #443 (?) but given how far the compilation process is progressing I suspect #443 has been resolved and can be closed?
I am using the requests-html package to scrape data from other pages (with JS content) to be inserted into a section of my page.
Test code is:

from requests_html import AsyncHTMLSession

asession = AsyncHTMLSession()

async def get_page1():
    r = await asession.get('https://python.org/')
    await r.html.arender()
    return r

async def get_page2():
    r = await asession.get('https://reddit.com/')
    await r.html.arender()
    return r

pages = asession.run(get_page1, get_page2)

and gives the following output/error:

(webdev) C:\Users\ustauss\Anaconda3Projects\ts_test>transcrypt -a -b -m -v rqhtstest.py

Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.7.16
Copyright (C) Geatec Engineering. License: Apache 2.0

Parsing module: c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/org/transcrypt/__runtime__.py
Generating code for module: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/org.transcrypt.__runtime__.js
Saving source map in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/org.transcrypt.__runtime__.map
Saving target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/org.transcrypt.__runtime__.js
Saving minified target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/org.transcrypt.__runtime__.js
Saving multi-level sourcemap in: {}
Parsing module: C:/Users/ustauss/Anaconda3Projects/ts_test/rqhtstest.py
Generating code for module: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/rqhtstest.js
Parsing module: c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/requests_html.py
Generating code for module: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/requests_html.js
Parsing module: c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/w3lib/encoding.py
Generating code for module: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/w3lib.encoding.js
Parsing module: c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/sys/__init__.py
Generating code for module: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/sys.js
Saving source map in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/sys.map
Saving target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/sys.js
Saving minified target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/sys.js
Saving multi-level sourcemap in: {}
Parsing module: c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/re/__init__.py
Generating code for module: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.js
Parsing module: c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/re/translate.py
Generating code for module: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.translate.js
Saving source map in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.translate.map
Saving target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.translate.js
Saving minified target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.translate.js
Saving multi-level sourcemap in: {}
Saving source map in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.map
Saving target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.js
Saving minified target code in: C:/Users/ustauss/Anaconda3Projects/ts_test/__target__/re.js
Saving multi-level sourcemap in: {}

Error while compiling (offending file last):
        File 'C:/Users/ustauss/Anaconda3Projects/ts_test/rqhtstest.py', line 1, at import of:
        File 'c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/requests_html.py', line 22, at import of:
        File 'w3lib.encoding', line 5, namely:

        Import error, can't find any of:
                C:/Users/ustauss/Anaconda3Projects/ts_test/re/translate/translate.py
                C:/Users/ustauss/Anaconda3Projects/ts_test/re/translate/translate.js
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/re/translate/translate.py
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/re/translate/translate.js
                C:/Users/ustauss/Anaconda3/envs/webdev/Scripts/transcrypt.exe/re/translate/translate.py
                C:/Users/ustauss/Anaconda3/envs/webdev/Scripts/transcrypt.exe/re/translate/translate.js
                c:/users/ustauss/anaconda3/envs/webdev/re/translate/translate.py
                c:/users/ustauss/anaconda3/envs/webdev/re/translate/translate.js
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/re/translate/translate.py
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/re/translate/translate.js
                C:/Users/ustauss/Anaconda3Projects/ts_test/re/translate.py
                C:/Users/ustauss/Anaconda3Projects/ts_test/re/translate.js
                C:/Users/ustauss/Anaconda3Projects/ts_test/codecs.py
                C:/Users/ustauss/Anaconda3Projects/ts_test/codecs.js
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/codecs.py
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/transcrypt/modules/codecs.js
                C:/Users/ustauss/Anaconda3/envs/webdev/Scripts/transcrypt.exe/codecs.py
                C:/Users/ustauss/Anaconda3/envs/webdev/Scripts/transcrypt.exe/codecs.js
                c:/users/ustauss/anaconda3/envs/webdev/codecs.py
                c:/users/ustauss/anaconda3/envs/webdev/codecs.js
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/codecs.py
                c:/users/ustauss/anaconda3/envs/webdev/lib/site-packages/codecs.js

Aborted

The __target__ subdirectory contains the following files:

org.transcrypt.__runtime__.js
org.transcrypt.__runtime__.map
org.transcrypt.__runtime__.pretty.map
org.transcrypt.__runtime__.py
re.js
re.map
re.pretty.map
re.py
re.translate.js
re.translate.map
re.translate.pretty.map
re.translate.py
sys.js
sys.map
sys.pretty.map
sys.py

Is Transcypt forgetting somewhere that it put those files (except codecs.*) into __target__?
What is going on?
Happy to provide any of the files in __target__ if necessary.

主要语言
Python
星标
2.9k
派生
218
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TranscryptOrg/Transcrypt 的其他 Issue

查看 TranscryptOrg/Transcrypt 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。