mhwgoo / fake_user_agent Goto Github PK
View Code? Open in Web Editor NEWRandomly generate a valid useragent for faking a browser.
License: MIT License
Randomly generate a valid useragent for faking a browser.
License: MIT License
Hi,
I recently installed fake_user_agent and have tried the following code only to get a KeyError
`from fake_user_agent import user_agent
ua = user_agent()
print(ua)`
Here is the full error:
Traceback (most recent call last):
File "C:\Users.....\PycharmProjects.............\snshop.py", line 6, in
ua = user_agent()
File "C:\Users......\virtualenvs...............\lib\site-packages\fake_user_agent\user_agent.py", line 263, in user_agent
return asyncio.run(main(browser, use_tempfile))
File "C:\Users............\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users...............\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "C:\Users.............\virtualenvs........\lib\site-packages\fake_user_agent\user_agent.py", line 216, in main
return random.choice(data[browser])
KeyError: 'opera'
[myuser@XXXX]$ python3
Python 3.10.1 (main, Dec 7 2021, 00:00:00) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fake_user_agent.main import user_agent
>>> user_agent("chrome")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/myuser/.local/lib/python3.10/site-packages/fake_user_agent/main.py", line 132, in user_agent
return asyncio.run(main(browser, use_tempfile))
File "/usr/lib64/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib64/python3.10/asyncio/base_events.py", line 641, in run_until_complete
return future.result()
File "/home/myuser/.local/lib/python3.10/site-packages/fake_user_agent/main.py", line 111, in main
return random_choose(browser, data)
File "/home/myuser/.local/lib/python3.10/site-packages/fake_user_agent/main.py", line 89, in random_choose
return random.choice(data[browser])
KeyError: 'chrome'
Is there any way that I can use fakeua
to print random ua directly(no asking for browser name)? I want to combine fakeua
into shell script.
$ echo `fakeua`
# I need to press enter here
Input a browser name or hit <enter> not to specify browser: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1500.55 Safari/537.36
By the way, Thank you. This project is fast and great.
Can we provide a "default" cache file, just in case the domain https://useragentstring.com/ is offline and the user has no cache?
Traceback (most recent call last):
File "C:\git\repo23\main.py", line 4452, in <module>
ua = user_agent()
File "C:\Program Files\Python39\lib\site-packages\fake_user_agent\main.py", line 132, in user_agent
return asyncio.run(main(browser, use_tempfile))
File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "C:\Program Files\Python39\lib\site-packages\fake_user_agent\main.py", line 111, in main
return random_choose(browser, data)
File "C:\Program Files\Python39\lib\site-packages\fake_user_agent\main.py", line 97, in random_choose
return random.choice(data[browser])
KeyError: 'chrome'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.