简体   繁体   中英

'coroutine' object has no attribute get || pyppeteer

In python, using pyppeteer , I am opening a webpage and running a JS script in its console and trying to capture the result in a variabl e but I am getting the following error.

Traceback (most recent call last):
  File "/home/ndaruto/anaconda3/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/naruto/anaconda3/lib/python3.7/site-packages/django/utils/deprecation.py", line 96, in __call__
    response = self.process_response(request, response)
  File "/home/naruto/anaconda3/lib/python3.7/site-packages/django/middleware/clickjacking.py", line 26, in process_response
    if response.get('X-Frame-Options') is not None:
AttributeError: 'coroutine' object has no attribute 'get'
/home/naruto/anaconda3/lib/python3.7/pathlib.py:704: RuntimeWarning: coroutine 'hmm' was never awaited


return self._str
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Below is the python code :-

async def hmm(request):
browser = await launch()
page = await browser.newPage()
await page.goto('http://jobs.chegg.com')
ans = await page.evaluate('''() => {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://cdnjs.cloudflare.com/ajax/libs/axe-core/3.1.2/axe.min.js';
    document.head.appendChild(script);
    setTimeout(function(){
    axe.run(document, {
        runOnly: {
        type: "tag",
        values: ["wcag2a", "wcag2aa", "best-practice"]
        },
        "rules": {
        "skip-link": { enabled: false }
        }
    }, function(err, results) {
        if (err) throw err;
        console.log(results);
    });
    }, 1000);
}''')
print("ANS IS", ans)
return 1

Can someone please suggest how to fix this?

AttributeError: 'coroutine' object has no attribute 'get' /home/naruto/anaconda3/lib/python3.7/pathlib.py:704: RuntimeWarning: coroutine 'hmm' was never awaited this means that you call hmm(request).get()
instead
r = await hmm(request) r.get()
somewhere in you code around this function

Going to need more context.

Your error doesn't reference any of the code in the script but there are references to unseen objects.

Sounds like you either missed an "await" somewhere or you need to call something with an aysnc factory.

I can help with that once I know more.

I would also suggest upgrading to 3.8 as Asyncio is somewhat recent to python and it can't hurt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM