-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersquestionFurther information is requestedFurther information is requested
Description
- I understand you have a section on async environments but it doesn't cover plain cases like how to use it with aiohttp
from swiftshadow.classes import ProxyInterface
async def test(url):
proxy_manager = ProxyInterface(autoUpdate=False,countries=["US"], protocol="http", autoRotate=True)
print(proxy_manager.get().as_string())
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0", # noqa: B950
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", # noqa: B950
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Cache-Control": "max-age=0",
}
text=''
async with aiohttp.ClientSession(headers=headers, timeout=aiohttp.ClientTimeout(total=30), trust_env=True, proxy=proxy_manager.get().as_string()) as session:
try:
async with session.get(url, raise_for_status=True, ssl=False) as response:
text = await response.text()
except Exception as e:
print(e)
return text
x=await test('https://bitcoinmagazine.com/feed')
- I am trying to load a url with aiohttp
- It gives me an error immediately
IndexError Traceback (most recent call last)
Cell In[49], [line 1](vscode-notebook-cell:?execution_count=49&line=1)
----> [1](vscode-notebook-cell:?execution_count=49&line=1) x=await test('https://bitcoinmagazine.com/feed')
Cell In[48], [line 4](vscode-notebook-cell:?execution_count=48&line=4)
2 async def test(url):
3 proxy_manager = ProxyInterface(autoUpdate=False,countries=["US"], protocol="http", autoRotate=True)
----> [4](vscode-notebook-cell:?execution_count=48&line=4) print(proxy_manager.get().as_string())
5 headers = {
6 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0", # noqa: B950
7 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", # noqa: B950
(...) 16 "Cache-Control": "max-age=0",
17 }
18 text=''
File /opt/homebrew/Cellar/jupyterlab/4.5.0/libexec/lib/python3.14/site-packages/swiftshadow/classes.py:315, in ProxyInterface.get(self)
301 """
302 Retrieves current active proxy.
303
(...) 311 ValueError: If no proxies are available (current is None).
312 """
314 if self.autorotate:
--> [315](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Cellar/jupyterlab/4.5.0/libexec/lib/python3.14/site-packages/swiftshadow/classes.py:315) self.rotate(validate_cache=self.autoUpdate)
316 if self.current:
...
352 if not len(seq):
--> [353](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Cellar/python@3.14/3.14.0_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/random.py:353) raise IndexError('Cannot choose from an empty sequence')
354 return seq[self._randbelow(len(seq))]
IndexError: Cannot choose from an empty sequence
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?8d1d4c23-6442-4a72-b218-259005d837d9) or open in a [text editor](command:workbench.action.openLargeOutput?8d1d4c23-6442-4a72-b218-259005d837d9). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
- I understand it has not updated the index but how do I fix this?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersquestionFurther information is requestedFurther information is requested