RapidTech1898
CACrawlee & Apify
•Created by RapidTech1898 on 5/30/2025 in #apify-platform
Store image to key-value-store?
Hello - i try to save an png-image to a key-value-store from a https-link using the following code:
kvs = await Actor.open_key_value_store(name='my-cool-key-value-store')
picLink = "https://rapidtech1898.com/wp-content/uploads/2023/11/openai_dall_created-560x320.png"
resp = requests.get(picLink, stream=True)
img = Image.open(resp.raw)
await kvs.set_value('explicit_image', img, content_type='image/png')
But i get this error:
TypeError: a bytes-like object is required, not 'PngImageFile'
[apify] INFO Exiting Actor ({"exit_code": 91})
Error: "C:\DEV.venv\apify\Scripts\python.exe" exited with code 91
How can i store the image to a key-valuie-store?
4 replies
CACrawlee & Apify
•Created by RapidTech1898 on 5/28/2025 in #apify-platform
Writing pdf / jpeg / zip to key-value-store?
Hello - i would like to store a file like pdf / image / zip in a key-value-store -
I can open the key-value-store with:
kvs = await Actor.open_key_value_store(name='my-cool-key-value-store')
But how can i write a pdf / jpeg / zip to this key-value-store now?
Here:
https://docs.apify.com/sdk/python/docs/concepts/storages
i can only see some examples for text / json / csv
await kvs.set_value('automatic_text', 'abcd')
await kvs.set_value('automatic_json', {'ab': 'cd'})
await kvs.set_value('explicit_csv', 'a,b\nc,d', content_type='text/csv')
How can i do this for pdf / jpeg / zip?
And is there somewhere an overview which content_type are possible?
9 replies
CACrawlee & Apify
•Created by RapidTech1898 on 5/27/2025 in #apify-platform
Debugging with keystroke using async actor?
Hello - im am testing with the basic template for python:
https://apify.com/templates/python-start
For debugging reasons i would like to output every heading and then waiting for a keystrike using <input("Press")> using the following code code below.
But when i press a key when running the program in the terminal i does not go to the next element.
How can i do this using async so i get every output after a keystroke?
Code:
from future import annotations
from apify import Actor
from bs4 import BeautifulSoup
from httpx import AsyncClient
async def main() -> None:
async with Actor:
actor_input = await Actor.get_input() or {'url': 'https://apify.com/'}
url = actor_input.get('url')
if not url:
raise ValueError('Missing "url" attribute in input!')
async with AsyncClient() as client: Actor.log.info(f'Sending a request to {url}') response = await client.get(url, follow_redirects=True) soup = BeautifulSoup(response.content, 'lxml') headings = [] for heading in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']): heading_object = {'level': heading.name, 'text': heading.text} Actor.log.info(f'Extracted heading: {heading_object}') input("Press!") headings.append(heading_object) await Actor.push_data(headings)
async with AsyncClient() as client: Actor.log.info(f'Sending a request to {url}') response = await client.get(url, follow_redirects=True) soup = BeautifulSoup(response.content, 'lxml') headings = [] for heading in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']): heading_object = {'level': heading.name, 'text': heading.text} Actor.log.info(f'Extracted heading: {heading_object}') input("Press!") headings.append(heading_object) await Actor.push_data(headings)
5 replies
CACrawlee & Apify
•Created by RapidTech1898 on 5/26/2025 in #apify-platform
Running actgor with different input-parameter?
Hello, i tired the following template for python:
https://apify.com/templates/python-selenium
worked generally fine.
But how can i run the actor with different urls?
(i tried to change the prefill url in input_schema.json but it seems allways stick to https://apify.com as url-input?)
4 replies
CACrawlee & Apify
•Created by RapidTech1898 on 5/25/2025 in #apify-platform
Error when running basic example from documentation
I try to run the example from this page:
https://docs.apify.com/sdk/python/docs/overview/running-actors-locally
Created this:
apify create my-first-actor --template python-start
Try to run the created actor:
apify run
And get this error:
TypeError: unhashable type: 'list'
Error: "C:\DEV.venv\apify\Scripts\python.exe" exited with code 1
More error-log:
(apify) C:\DEV\Python-Diverses\Apify_Development\my-first-actor>apify run
Warning: The storage directory contains a previous state, the Actor will continue where it left off. To start from the initial state, use --purge parameter to clean the storage directory.
Warning: You are not logged in with your Apify Account. Some features like Apify Proxy will not work. Call "apify login" to fix that.
TypeError: unhashable type: 'list'
Error: "C:\DEV.venv\apify\Scripts\python.exe" exited with code 1
Why is the example from you documentation not working?
5 replies