Closed polarflex closed 9 months ago
Can you send the pcpartpicker link you're using?
-CorpNewt
Here it is: https://pcpartpicker.com/list/8JdBGP
I tried using it without https:// before as well.
It appears to work fine on my instance of the bot. You could look into adding some debug prints in the PCPP.py file and see if that reveals anything else.
-CorpNewt
I'll try redownloading the source and reconfiguring it again, if that doesn't work I'll see if I can debug it.
Sounds good, please let me know how it goes.
-CorpNewt
Just reinstalled it, maybe there is something that I haven't setup but I still got the same error:
Gonna see if I can add the prints now.
Just leads me to the if condition:
print(f"Processing PCPP command with URL: {url}, Style: {style}, Escape: {escape}") output = await PCPP.getMarkdown(url, style, escape) if not output: print("PCPP command failed. Invalid pcpartpicker link.") msg = 'Something went wrong! Make sure you use a valid pcpartpicker link.' return await ctx.send(msg) if len(output) > 2000: msg = "That's an *impressive* list of parts - but the max length allowed for messages in Discord is 2000 characters, and you're at *{}*.".format(len(output)) msg += '\nMaybe see if you can prune up that list a bit and try again?' return await ctx.send(msg) print("PCPP command successful. Sending output.") await ctx.send(output)
Erm the code wasn't supposed to be like that, here's a screenshot for better readability:
Maybe try commenting out the try/except here and see if it throws an exception: https://github.com/corpnewt/CorpBot.py/blob/rewrite/Cogs/PCPP.py#L125
It may also be related to the User-Agent passed, but I would think that would prevent it from working for me as well.
Yes it did, here's the full log: Ignoring exception in command pcpp: Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 178, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\user\Desktop\CorpBot.py-rewrite\Cogs\Hw.py", line 96, in pcpp output = await PCPP.getMarkdown(url, style, escape) File "C:\Users\user\Desktop\CorpBot.py-rewrite\Cogs\PCPP.py", line 134, in getMarkdown for i in response.split("\n"): UnboundLocalError: local variable 'response' referenced before assignment
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 347, in invoke await ctx.command.invoke(ctx) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 950, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 187, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnboundLocalError: local variable 'response' referenced before assignment
You'd still need the line where response
is set, just comment out (or remove) the try/except stuffs. The following line still needs to be there:
response = await DL.async_text(url,{"user-agent":"Mozilla"})
You can also try removing the User-Agent:
response = await DL.async_text(url)
Got this error now:
Processing PCPP command with URL: https://pcpartpicker.com/list/sJdBGP, Style: normal, Escape: False Ignoring exception in command pcpp: Traceback (most recent call last): File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 178, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\Hw.py", line 96, in pcpp output = await PCPP.getMarkdown(url, style, escape) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\PCPP.py", line 127, in getMarkdown response = await DL.async_text(url,{"user-agent":"Mozilla"}) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\DL.py", line 48, in async_text data = await async_dl(url, headers, ssl) File "C:\Users\chima\Desktop\CorpBot.py-rewrite\Cogs\DL.py", line 34, in async_dl assert response.status == 200 AssertionError
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 347, in invoke await ctx.command.invoke(ctx) File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 950, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\chima\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 187, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AssertionError:
I tried removing the user agent as well
Yeah, pcpartpicker is returning a status that is not 200, which means something is wrong reaching the site/loading the URL. It's likely a network error of some kind, but I don't know beyond that. You can edit DL.py to print what the status code is and see, but I would bet it's a 403 forbidden or similar. If you have a VPN, try changing your connection or similar.
Yes I got: assert response.status == 200, f"status isn't ok: {response.status}, url: {url}" AssertionError: status isn't ok: 403, url: https://pcpartpicker.com/list/sJdBGP
pcpp hates me :(
It does sound like it's quite angry with you :/
You can try a VPN, another computer, etc - but I'm not sure what else to tell you. I hope you're able to get the issue resolved, but as it's not a problem with the bot itself I'll close this issue thread.
-CorpNewt
This is quite old now, but I tried it on an Azure Linux Server and I still had the same problem, if you are using a hosting which one are you using?
I run the bot on a local machine - and I have not had any issues with PCPP.
-CorpNewt
Alright thanks I'll get my friend to try it
Hopefully that's all it is!
-CorpNewt
I could be stupid, however whenever I try to use the $pcpp list, whatever link I try or whatever I do, the bot always responds with: Something went wrong! Make sure you use a valid pcpartpicker link.
Along with that, the autopcpp command once sent it says "Auto pcpartpicker disabled", afterwards if you send it again it doesn't reply with anything, and once again after sending that it just says "Auto pcpartpicker disabled". After "turning on" the autopcpp command, and sending a link, the bot does nothing.