This is my environment:
ubuntu18.04(wsl2)
playwright 1.29.1
pyee 8.22
scrapy-playwright 0.024
Here is my code:
import asyncio
from playwright.async_api import async_playwright
import time
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch_persistent_context(headless=False, user_data_dir='', args=['--disable-infobars'])
page = await browser.new_page()
await page.goto('https://www.baidu.com')
time.sleep(100)
await page.close()
asyncio.run(main())
Here is my traceback:
Traceback (most recent call last):
File "/home/edmounds/tieba/test2.py", line 2, in <module>
from playwright.async_api import async_playwright
File "/home/edmounds/.local/lib/python3.9/site-packages/playwright/async_api/__init__.py", line 25, in <module>
import playwright.async_api._generated
File "/home/edmounds/.local/lib/python3.9/site-packages/playwright/async_api/_generated.py", line 25, in <module>
from playwright._impl._accessibility import Accessibility as AccessibilityImpl
File "/home/edmounds/.local/lib/python3.9/site-packages/playwright/_impl/_accessibility.py", line 17, in <module>
from playwright._impl._connection import Channel
File "/home/edmounds/.local/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 25, in <module>
from pyee.asyncio import AsyncIOEventEmitter
ModuleNotFoundError: No module named 'pyee.asyncio'
I have checked the pyee package.
I also tried import pyee, but it didn't work.
Make sure you do
pip install playwright
Then run the command
playwright install
This may take a while but that's what I did and it worked.
Related
I'm trying to use flask-ask library and develope a skill that can make me able to control a robot in ROS with alexa vocal assistant. Python code named "alexa_interface.py" is here.
The skill id number is substituted with my skill id number.
While launching this command
python3 alexa_interface.py
I am getting the following code error.
Tried to install dependencies with pip but getting:
AttributeError: module 'lib' has no attribute 'ERR_load_RAND_strings'
Also notice that I am getting this error everytime I use pip to install something. Is pip broken? How can I adjust this?
Thank you.
#! /usr/bin/env python3
from flask import Flask
from ask_sdk_core.skill_builder import SkillBuilder
from flask_ask_sdk.skill_adapter import SkillAdapter
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.utils import is_request_type, is_intent_name
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
from ask_sdk_model.ui import SimpleCard
app = Flask(__name__)
class LaunchRequestHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_request_type("LaunchRequest")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Ciao, come posso aiutarti?"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response`
skill_builder = SkillBuilder()
# Register your intent handlers to the skill_builder object
skill_builder.add_request_handler(LaunchRequestHandler())
skill_adapter = SkillAdapter(
skill=skill_builder.create(), skill_id="my-skill-id", app=app)
skill_adapter.register(app=app, route="/")
if __name__=='__main__':
app.run()
```
```
Traceback (most recent call last):
File "alexa_interface.py", line 2, in <module>
from flask import Flask
File "/home/toti/.local/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/home/toti/.local/lib/python3.8/site-packages/jinja2/__init__.py)
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in <module>
import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket
File "/usr/lib/python3/dist-packages/requests_unixsocket/__init__.py", line 1, in <module>
import requests
File "/home/toti/.local/lib/python3.8/site-packages/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/home/toti/.local/lib/python3.8/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/home/toti/.local/lib/python3.8/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/home/toti/.local/lib/python3.8/site-packages/OpenSSL/rand.py", line 213, in <module>
_lib.ERR_load_RAND_strings()
AttributeError: module 'lib' has no attribute 'ERR_load_RAND_strings'
Original exception was:
Traceback (most recent call last):
File "alexa_interface.py", line 2, in <module>
from flask import Flask
File "/home/toti/.local/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/home/toti/.local/lib/python3.8/site-packages/jinja2/__init__.py)
```
I'm trying to accommodate slash commands in a discord bot I'm working on and I'm using the discord-ui package for this. I would just like to get some advice on this error and how to fix it
AttributeError: module 'discord' has no attribute 'StoreChannel'
The code is
import discord, os
from discord.ext import commands
from discord_ui import UI, SlashOption
client = commands.Bot(" ")
ui = UI(client)
#ui.slash.command("hello_world", options=[SlashOption(bool, "cool", "whether this libary is cool", required=False)])
async def command(ctx, cool=True):
await ctx.respond("You said this libary is " + str(cool))
for more details on the error:
Traceback (most recent call last):
File "/./Bot1/main.py", line 4, in <module>
from discord_ui import UI, SlashOption
File "/.local/lib/python3.9/site-packages/discord_ui/__init__.py", line 34, in <module>
from .client import *
File "/.local/lib/python3.9/site-packages/discord_ui/client.py", line 1, in <module>
from .cogs import BaseCallable, InteractionableCog, ListeningComponent
File "/.local/lib/python3.9/site-packages/discord_ui/cogs.py", line 5, in <module>
from .slash.types import BaseCommand, ContextCommand, MessageCommand, SlashCommand, SlashSubcommand, UserCommand
File "/.local/lib/python3.9/site-packages/discord_ui/slash/__init__.py", line 20, in <module>
from . import ext
File "/.local/lib/python3.9/site-packages/discord_ui/slash/ext/__init__.py", line 13, in <module>
from .builder import *
File "/.local/lib/python3.9/site-packages/discord_ui/slash/ext/builder.py", line 2, in <module>
from ...enums import CommandType, OptionType
File "/.local/lib/python3.9/site-packages/discord_ui/enums.py", line 13, in <module>
discord.StoreChannel,
EDIT:
After following xcodz-dot's suggestion, while it was helpful and I believed it has fixed one problem, I recieved an exception in client.py. Traceback:
Traceback (most recent call last):
File "/workspaces/[repo_name]/resource.py", line 5, in <module>
from discord_components import DiscordComponents, ButtonStyle, Button
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord_components/__init__.py", line 1, in <module>
from .client import *
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord_components/client.py", line 3, in <module>
from discord import (
ImportError: cannot import name 'Guild' from 'discord' (/opt/python/3.10.4/lib/python3.10/site-packages/discord/__init__.py)
Is this a seperate issue or is it in direct causation of changing asyncio.async to getattr(asyncio, "async") in both compat.py and compatibility.py?
Please help me, thx :)
===============================================================
BELOW: OLD QUESTION, LIKELY RESOLVED
I am using Github Codespaces, and in the process of programming my bot, when trying to import discord_components, a SyntaxError is raised. Traceback (bash terminal, linux vm):
#[username]➜ /workspaces/[repo_name] (main ✗) $ /opt/python/latest/bin/python /workspaces/SineBot/resource.py
Traceback (most recent call last):
File "/workspaces/[repo_name]/resource.py", line 4, in <module>
from discord_components import DiscordComponents, ButtonStyle, Button
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord_components/__init__.py", line 1, in <module>
from .client import *
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord_components/client.py", line 3, in <module>
from discord import (
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord/__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord/client.py", line 38, in <module>
from .state import ConnectionState
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord/state.py", line 36, in <module>
from . import utils, compat
File "/opt/python/3.10.4/lib/python3.10/site-packages/discord/compat.py", line 32
create_task = asyncio.async
^^^^^
SyntaxError: invalid syntax
I have tried all soloutions in create_task = asyncio.async: SyntaxError: invalid syntax, except for downgrading to Py3.5 and using rewrite.zip (because it doesn't even exist), but there are functionalities in Py3.10 that I need, and downgrading would be a nightmare, if not, impossible. Note that discord.py works on my local machine.
Here is combat.py for reference:
...
import concurrent.futures
import asyncio
try:
create_task = asyncio.ensure_future
except AttributeError:
create_task = asyncio.async # -> where the exception is happening
try:
run_coroutine_threadsafe = asyncio.run_coroutine_threadsafe
except AttributeError:
...
The same exception is raised when discord.py is imported (before discord_components).
Please help :)
In python 3.10, async is a keyword just like any other keyword such as while, for, etc... So you cannot write it like that. As far as I can see you are trying to be backwards compatible so you can use getattr builtin function which will resolve the error
...
import concurrent.futures
import asyncio
try:
create_task = asyncio.ensure_future
except AttributeError:
create_task = getattr(asyncio, "async") # -> where the exception is happening
try:
run_coroutine_threadsafe = asyncio.run_coroutine_threadsafe
except AttributeError:
...
I am trying to make a discord bot, but I get the following weird error where it can not import asyncio.Transport, although I am able to use it normally outside this code.
The code:
import asyncio
import os
import discord
from dotenv import load_dotenv
The error message:
Traceback (most recent call last):
File "dis.py", line 1, in <module>
import asyncio
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\asyncio\__init__.py", line 21, in <module>
from .base_events import *
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", line 19, in <module>
import inspect
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\inspect.py", line 36, in <module>
import dis
File "C:\Users\A.Gawish\dis.py", line 3, in <module>
import discord
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\__init__.py", line 23, in <module>
from .client import Client
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 34, in <module>
import aiohttp
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\__init__.py", line 6, in <module>
from .client import (
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\client.py", line 32, in <module>
from . import hdrs, http, payload
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\http.py", line 7, in <module>
from .http_parser import (
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\http_parser.py", line 14, in <module>
from .base_protocol import BaseProtocol
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\base_protocol.py", line 4, in <module>
from .tcp_helpers import tcp_nodelay
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\tcp_helpers.py", line 20, in <module>
def tcp_keepalive(transport: asyncio.Transport) -> None:
AttributeError: module 'asyncio' has no attribute 'Transport'
Your filename was dis.py, which is used in another module. I resolved a similar issue by ensuring the filename is different from any other existing files in Lib
If you look at your error messages, it is indicating Python36. If Transport in asyncio was only released in Python37, you need to change the pathing in whatever program you're using to write the code in as it's looking at Python36.
Testing it as the command prompt would show that your system sees Python37 but your code doesn't. Fix the pathing and it should work then.
I'm new to python, and I was creating a Bot to discord by PyCharm when suddenly there was this giant error below, I already reinstalled python, tried configuring the PATHs for python 3.7 and 3.6, changed IDE and continues giving this error, can anyone help me figure out what's causing this?
error below:
C:\Users\Pichau\AppData\Local\Programs\Python\Python36\python.exe C:/Users/Pichau/Documents/cursos/programacao/Discord/main.py
Traceback (most recent call last):
File "C:/Users/Pichau/Documents/cursos/programacao/Discord/main.py", line 1, in <module>
import discord
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 28, in <module>
from .user import User
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\user.py", line 27, in <module>
from .utils import snowflake_time
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\utils.py", line 31, in <module>
import asyncio
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\asyncio\__init__.py", line 21, in <module>
from .base_events import *
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", line 17, in <module>
import concurrent.futures
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 7, in <module>
import logging
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, traceback, warnings, weakref, collections
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\Pichau\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 41, in <module>
__all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding",
AttributeError: module 'token' has no attribute '__all__'
Process finished with exit code 1
Image of error
I would check the code, unless it won’t let you, then you should probably put the code in notepad, and save it then delete the file, and try again. It probably is a computer error more then a coding error.