'MechanicalSoup nothing to repeat at position 0
import argparse
from getpass import getpass
import mechanicalsoup
parser = argparse.ArgumentParser(description="Login to Northwest.1")
parser.add_argument("username")
args = parser.parse_args()
args.password = getpass("Please enter your Northwest password: ")
browser = mechanicalsoup.StatefulBrowser()
browser.open("https://thenorthwest.myatonce.com/login")
browser.select_form('#login-form')
browser["username"] = args.username
browser["password"] = args.password
resp = browser.submit_selected()
browser.follow_link("catalog")
browser.follow_link("?cl=45&gndr=65")
browser.launch_browser()
Well, uh. I can follow the link to catalog, https://thenorthwest.myatonce.com/catalog/ so there is no problem with login and forwarding to catalog but I cannot follow the link to the specified catalog page. https://thenorthwest.myatonce.com/catalog/?cl=45&gndr=65 Can anyone help?
FULL ERROR CODE AND POSSIBLE FLASHBANG ALERT BELOW
Traceback (most recent call last):
File "C:\Users\emosc\PycharmProjects\achyls\main.py", line 14, in <module>
browser.follow_link("login")
l_browser.py", line 354, in follow_link
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 324, in _find_link_internal
return self.find_link(*args, **kwargs)
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 298, in find_link
raise LinkNotFoundError()
mechanicalsoup.utils.LinkNotFoundError
PS C:\Users\emosc\PycharmProjects\achyls> py main.py anatoliawholesale
Please enter your Northwest password:
PS C:\Users\emosc\PycharmProjects\achyls> py main.py anatoliawholesale
Please enter your Northwest password:
Traceback (most recent call last):
File "C:\Users\emosc\PycharmProjects\achyls\main.py", line 18, in <module>
browser.follow_link("?cl=45&gndr=64")
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 354, in follow_link
link = self._find_link_internal(link, bs4_args,
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 324, in _find_link_internal
return self.find_link(*args, **kwargs)
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 296, in find_link
links = self.links(*args, **kwargs)
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 281, in links
all_links = [a for a in all_links
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 282, in <listcomp>
if re.search(url_regex, a['href'])]
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\re.py", line 200, in sea
rch
return _compile(pattern, flags).search(string)
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\re.py", line 303, in _co
mpile
p = sre_compile.compile(pattern, flags)
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\sre_compile.py", line 76
4, in compile
p = sre_parse.parse(p, flags)
in parse
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\sre_parse.py", line 443,
in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\sre_parse.py", line 668,
in _parse
raise source.error("nothing to repeat",
re.error: nothing to repeat at position 0
PS C:\Users\emosc\PycharmProjects\achyls> py main.py anatoliawholesale
Please enter your Northwest password:
PS C:\Users\emosc\PycharmProjects\achyls> py main.py anatoliawholesale
Please enter your Northwest password:
Traceback (most recent call last):
File "C:\Users\emosc\PycharmProjects\achyls\main.py", line 19, in <module>
browser.follow_link("?cl=45&gndr=65")
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 354, in follow_link
link = self._find_link_internal(link, bs4_args,
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 324, in _find_link_internal
return self.find_link(*args, **kwargs)
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 296, in find_link
links = self.links(*args, **kwargs)
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 281, in links
all_links = [a for a in all_links
File "C:\Users\emosc\PycharmProjects\achyls\venv\lib\site-packages\mechanicalsoup\statefu
l_browser.py", line 282, in <listcomp>
if re.search(url_regex, a['href'])]
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\re.py", line 200, in sea
rch
return _compile(pattern, flags).search(string)
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\re.py", line 303, in _co
mpile
p = sre_compile.compile(pattern, flags)
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\sre_compile.py", line 76
4, in compile
p = sre_parse.parse(p, flags)
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\sre_parse.py", line 948,
in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\sre_parse.py", line 443,
in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "C:\Users\emosc\AppData\Local\Programs\Python\Python310\lib\sre_parse.py", line 668,
in _parse
raise source.error("nothing to repeat",
re.error: nothing to repeat at position 0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
