Why Aren't Streamlit and Playwright Playing Nicely Together (Solving NotImplementedError)? - python

I’m trying to use Playwright with streamlit on Windows using Python, and I keep getting a NotImplementedError. Here’s a simple Streamlit app, using the hello-world example from playwright’s Python documentation:
import streamlit as st
from playwright.sync_api import sync_playwright
st.write(“Starting the test…”)
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto(http://playwright.dev)
st.write((page.title())
browser.close()
And here’s the error message:
NotImplementedError
Traceback:
File “c:\users\aschneiderman\anaconda3\lib\site-packages\streamlit\scriptrunner\script_runner.py”, line 557, in _run_script
exec(code, module.dict)
File “app.py”, line 6, in
with sync_playwright() as p:
File “c:\users\aschneiderman\anaconda3\lib\site-packages\playwright\sync_api_context_manager.py”, line 87, in enter
dispatcher_fiber.switch()
File “c:\users\aschneiderman\anaconda3\lib\site-packages\playwright\sync_api_context_manager.py”, line 67, in greenlet_main
self._loop.run_until_complete(self._connection.run_as_sync()) this
File “c:\users\aschneiderman\anaconda3\lib\asyncio\base_events.py”, line 616, in run_until_complete
return future.result()
File “c:\users\aschneiderman\anaconda3\lib\site-packages\playwright_impl_connection.py”, line 210, in run_as_sync
await self.run()
File “c:\users\aschneiderman\anaconda3\lib\site-packages\playwright_impl_connection.py”, line 219, in run
await self._transport.connect()
File “c:\users\aschneiderman\anaconda3\lib\site-packages\playwright_impl_transport.py”, line 139, in connect
raise exc
File “c:\users\aschneiderman\anaconda3\lib\site-packages\playwright_impl_transport.py”, line 127, in connect
self._proc = await asyncio.create_subprocess_exec(
File “c:\users\aschneiderman\anaconda3\lib\asyncio\subprocess.py”, line 236, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
File “c:\users\aschneiderman\anaconda3\lib\asyncio\base_events.py”, line 1630, in subprocess_exec
transport = await self._make_subprocess_transport(
File “c:\users\aschneiderman\anaconda3\lib\asyncio\base_events.py”, line 491, in _make_subprocess_transport
raise NotImplementedError
I did some googling and couldn’t find anything. Any thoughts on how to diagnose what’s going wrong and how to fix it?

Related

I can’t locally launch the streamlit app through jupyter notebook, it showed runtimeerror

I am new to using the Streamlit app. I used jupyternotebook to locally run the first app using Streamlit. Below is my code:
import streamlit as st
#writing simple text
st.text("Hello")
Then, I run the command below in anaconda command prompt.
streamlit run C:\Users\User\anaconda3\envs\webapp\lib\site-packages\ipykernel_launcher.py
Then, I got the popup window with error message as showed below.
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 554, in _run_script
exec(code, module.__dict__)
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\traitlets\config\application.py", line 845, in launch_instance
app.initialize(argv)
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\traitlets\config\application.py", line 88, in inner
return method(app, *args, **kwargs)
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\ipykernel\kernelapp.py", line 647, in initialize
self.init_kernel()
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\ipykernel\kernelapp.py", line 493, in init_kernel
shell_stream = ZMQStream(self.shell_socket)
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\zmq\eventloop\zmqstream.py", line 101, in __init__
self.io_loop = io_loop or IOLoop.current()
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\zmq\eventloop\ioloop.py", line 130, in current
loop = ioloop.IOLoop.current(*args, **kwargs)
File "C:\Users\User\anaconda3\envs\webapp\lib\site-packages\tornado\ioloop.py", line 263, in current
loop = asyncio.get_event_loop()
File "C:\Users\User\anaconda3\envs\webapp\lib\asyncio\events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
Below is how the web browser shows.
How do I resolve this issue? Can I actually run the Streamlit app through the Jupyternotebook?
Thanks for any suggestions you may provide.

RuntimeWarning: coroutine 'current_time' was never awaited return float(anyio.current_time())

python 3.8.8
httpx 0.18.2
This is my code below. I am test with httpx&asyncio.Code is very simple and same as example, but error occured.
headers = {"Content-type":"text/html", "charset":"UTF-8"}
async def gethtml(url):
async with httpx.AsyncClient(headers=headers, verify=False) as client:
r = await client.get(url)
return r.status_code
url = 'http://www.google.com'
asyncio.run(gethtml(url))
when I run it, an issue occur.
RuntimeWarning: coroutine 'current_time' was never awaited
return float(anyio.current_time())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-12f16719e1ee>", line 1, in <module>
runfile('/Users/yilu/Documents/7k/aaa.py', wdir='/Users/yilu/Documents/7k/')
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/yilu/Documents/7k/aaa.py", line 53, in <module>
asyncio.run(gethtml(url))
File "/Users/yilu/opt/anaconda3/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Users/yilu/opt/anaconda3/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/Users/yilu/Documents/7k/aaa.py", line 17, in gethtml
r = await client.get(url)
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1722, in get
return await self.request(
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1481, in request
response = await self.send(
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1568, in send
response = await self._send_handling_auth(
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1604, in _send_handling_auth
response = await self._send_handling_redirects(
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1640, in _send_handling_redirects
response = await self._send_single_request(request, timeout)
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_client.py", line 1681, in _send_single_request
) = await transport.handle_async_request(
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpx/_transports/default.py", line 283, in handle_async_request
) = await self._pool.handle_async_request(
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_async/http_proxy.py", line 102, in handle_async_request
await self._keepalive_sweep()
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 303, in _keepalive_sweep
now = await self._backend.time()
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_backends/auto.py", line 64, in time
return await self.backend.time()
File "/Users/yilu/opt/anaconda3/lib/python3.8/site-packages/httpcore/_backends/anyio.py", line 198, in time
return float(anyio.current_time())
TypeError: float() argument must be a string or a number, not 'coroutine'
when I ran it by python 3.7 before ,it is normal. But now, I can't deal with it.
Could you some one help me? Thank you
When I reduce the httpx version to 0.17.1, this issue get been resovled.
So I think it maybe the bug on httpx

Using apscheduler with asyncpg db as Job Store: Error MissingGreenlet

I'm trying to use Apscheduler with a postgresql db via an asyncpg connection. I thought it would working, because asyncpg supports sqlalchemy ref. But yeah, it isn't working. And to make it even worst, I don't understand the error message, so I have not even a guess what to google for.
import asyncio
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
def simple_job():
print('This was an easy job!')
scheduler = AsyncIOScheduler()
jobstore = SQLAlchemyJobStore(url='postgresql+asyncpg://user:password#localhost:5432/public')
scheduler.add_jobstore(jobstore)
# schedule a simple job
scheduler.add_job(simple_job, 'cron', second='15', id='heartbeat',
coalesce=True, misfire_grace_time=5, replace_existing=True)
scheduler.start()
Versions:
python 3.7
APScheduler==3.7.0
asyncpg==0.22.0
SQLAlchemy==1.4.3
Error Message and traceback:
Traceback (most recent call last):
File "C:/Users/d/PycharmProjects/teamutils/utils/automation.py", line 320, in <module>
scheduler.start()
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\apscheduler\schedulers\asyncio.py", line 45, in start
super(AsyncIOScheduler, self).start(paused)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\apscheduler\schedulers\base.py", line 163, in start
store.start(self, alias)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\apscheduler\jobstores\sqlalchemy.py", line 68, in start
self.jobs_t.create(self.engine, True)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\sql\schema.py", line 940, in create
bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py", line 2979, in _run_ddl_visitor
with self.begin() as conn:
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py", line 2895, in begin
conn = self.connect(close_with_result=close_with_result)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py", line 3067, in connect
return self._connection_cls(self, close_with_result=close_with_result)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py", line 91, in __init__
else engine.raw_connection()
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py", line 3146, in raw_connection
return self._wrap_pool_connect(self.pool.connect, _connection)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py", line 3113, in _wrap_pool_connect
return fn()
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py", line 301, in connect
return _ConnectionFairy._checkout(self)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py", line 755, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py", line 419, in checkout
rec = pool._do_get()
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\impl.py", line 145, in _do_get
self._dec_overflow()
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\compat.py", line 198, in raise_
raise exception
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\impl.py", line 142, in _do_get
return self._create_connection()
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py", line 247, in _create_connection
return _ConnectionRecord(self)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py", line 362, in __init__
self.__connect(first_connect_check=True)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py", line 605, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\compat.py", line 198, in raise_
raise exception
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py", line 599, in __connect
connection = pool._invoke_creator(self)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\create.py", line 578, in connect
return dialect.connect(*cargs, **cparams)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\default.py", line 548, in connect
return self.dbapi.connect(*cargs, **cparams)
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 744, in connect
await_only(self.asyncpg.connect(*arg, **kw)),
File "C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 48, in await_only
"greenlet_spawn has not been called; can't call await_() here. "
sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_() here. Was IO attempted in an unexpected place? (Background on this error at: http://sqlalche.me/e/14/xd2s)
sys:1: RuntimeWarning: coroutine 'connect' was never awaited
I looked up the provided link, but not getting smart of it. So it would be nice, if somebody can tell me what is going on, so I can search for a solution by my own. (a solution would okay too, of course xD)
Sorry for this "open" question, but my understanding is so bad, that I dont know what to ask for.
I think problem is in ApScheduler.
What is happening is that scheduler.start() will attempt to create the job table in your database. But since your database url is specified as +asyncpg and there is no async coroutine running (ie: async def) when ApScheduler tries to create the table. Hence the "coroutine 'connect' was never awaited" error.
After reading the ApScheduler code, I think "integrates with asyncio" is a little misleading - specifically the scheduler can run asyncio, but the JobStore itself has no provision for an asyncio database connection.
You can get it working by removing +asyncpg in the connection url used with ApScheduler.
Note it would still be possible to use async db calls within job functions with a separate asyncpg connection.

(Python) Unable to create process using '-'

Okay. This is complicated for me to explain, but I'll try my best:
it starts when one day I decide to run and test my Discord bot (using discord.py) when I'm greeted with this error:
TypeError: __new__() got an unexpected keyword argument 'deny_new'
If needed, the full traceback:
File "script.py", line 14, in <module>
bot.run('token')
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 640, in run
return future.result()
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 621, in runner
await self.start(*args, **kwargs)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 585, in start
await self.connect(reconnect=reconnect)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 499, in connect
await self._connect()
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 463, in _connect
await self.ws.poll_event()
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\gateway.py", line 471, in poll_event
await self.received_message(msg)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\gateway.py", line 425, in received_message
func(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\state.py", line 750, in parse_guild_create
guild = self._get_create_guild(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\state.py", line 725, in _get_create_guild
guild._from_data(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\guild.py", line 297, in _from_data
self._sync(guild)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\guild.py", line 324, in _sync
self._add_channel(TextChannel(guild=self, data=c, state=self._state))
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\channel.py", line 107, in __init__
self._update(guild, data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\channel.py", line 131, in _update
self._fill_overwrites(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\abc.py", line 294, in _fill_overwrites
self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
TypeError: __new__() got an unexpected keyword argument 'deny_new'
I looked up this issue and found a resolution to this problem - to just reinstall discord.py. So:
> pip uninstall discord
Another error:
Unable to create process using 'C:\Users\44794\aanaconda3\python.exe C:\Users\44794\aanaconda3\Scripts\pip-script.py uninstall discord'
I'm sure that once I have the solution to this issue, the other problems can be fixed easily.
As always, I've only been properly using Python for two months or so. Please try to simplify the solution as best you can! Thanks in advance.

Error loading discord bot on startup. hosted through repl.it

A couple days ago my discord bot suddenly went offline, i host my bot through repl.it and i cant get it to work as it gives a dirty error.
Traceback (most recent call last):
File "main.py", line 584, in <module>
bot.run("NTg0NjkyODA1NTcwNjU4MzEz.XPOnmw.VpE_ILHaDdQ6k--OIBRovc1h80o")
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 640, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 621, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 585, in start
await self.connect(reconnect=reconnect)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 499, in connect
await self._connect()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 463, in _connect
await self.ws.poll_event()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/gateway.py", line 471, in poll_even
t
await self.received_message(msg)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/gateway.py", line 425, in received_
message
func(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/state.py", line 750, in parse_guild
_create
guild = self._get_create_guild(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/state.py", line 725, in _get_create_guild
guild._from_data(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 297, in _from_data
self._sync(guild)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 328, in _sync
self._add_channel(CategoryChannel(guild=self, data=c, state=self._state))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/channel.py", line 726, in __init__
self._update(guild, data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/channel.py", line 737, in _update
self._fill_overwrites(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 294, in _fill_overwrites
self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
TypeError: __new__() got an unexpected keyword argument 'deny_new'
this is in the console and i dont know what it means. we didnt change any code, nothing it just went offline and stop working.
Just update the discord.py module. Discord switched the api domain from discordapp.com to discord.com. That is the reason for the code crashing.
You can just go to packages and uninstall the current discord.py module. Then re-add it. There is no feature to directly update the discord.py module. SO u have to uninstall and re-install. [worked for me]

Categories

Resources