Bug 425129

Summary: Amazon search delivers error message "access to restricted port in post denied"
Product: [Applications] tellico Reporter: frog
Component: generalAssignee: Robby Stephenson <robby>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 3.3.1   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 3.3.3
Sentry Crash Report:

Description frog 2020-08-08 07:21:25 UTC
SUMMARY
Amazon search delivers error message "access to restricted port in post denied", regardless if you search for title or ISBN. Search with other engines yield results.

STEPS TO REPRODUCE
1. search via Amazon
2. select title 
3. enter "Harry Potter"

OBSERVED RESULT
error message: "access to restricted port in post denied"

EXPECTED RESULT
Book info

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: KaOS
(available in About System)
KDE Plasma Version: 5.19
KDE Frameworks Version: 5.70
Qt Version: 5.15

ADDITIONAL INFORMATION
Comment 1 Robby Stephenson 2020-08-08 18:24:12 UTC
Have you gotten new credentials for API v5? https://webservices.amazon.com/paapi5/documentation/register-for-pa-api.html notably "Product Advertising API sign up is available only to associates who have referred qualified sales and have been accepted into the program."

Debugging with the Amazon API is challenging with their new API since I don't have access. You can see a little more info here: https://tellico-project.org/searching-amazon-may-not-work-after-march/

If you can run Tellico from the command line with an environmental variable to log the Amazon data, then send it to me, that would be helpful. You can just run from the terminal:
TELLICO_ENABLE_AMAZON_LOG=1 tellico

Then do an amazon search. You should see a message in the terminal about data output going to a temporary file, which is the one to send. Thanks for you help.
Comment 2 frog 2020-08-14 13:38:17 UTC
This is what I get after calling the Amazon service
f5.kio.core: Invalid URL: QUrl("")
org.kde.knotifications: Audio notification requested, but sound file from notifyrc file was not found, aborting audio notification
Comment 3 Robby Stephenson 2020-08-14 15:41:41 UTC
(In reply to frog from comment #2)
> This is what I get after calling the Amazon service
> f5.kio.core: Invalid URL: QUrl("")
> org.kde.knotifications: Audio notification requested, but sound file from
> notifyrc file was not found, aborting audio notification

If you can run Tellico from the command line with an environmental variable to log the Amazon data, then send it to me, that would be helpful. You can just run from the terminal:
TELLICO_ENABLE_AMAZON_LOG=1 tellico

then send me the log file.
Comment 4 frog 2020-08-14 19:17:23 UTC
Thank you for helping me. 
I can't find the file. Where should it be?
Comment 5 Robby Stephenson 2020-08-14 19:37:17 UTC
(In reply to frog from comment #4)
> Thank you for helping me. 
> I can't find the file. Where should it be?

Ah, so there's no message in the terminal with the file name? It's in your tmp folder, which is likely /tmp and the file name starts with amazon-search-items-

Sorry - I didn't realize the file location wasn't being shown
Comment 6 frog 2020-08-14 21:43:00 UTC
(In reply to Robby Stephenson from comment #5)
> 
> Ah, so there's no message in the terminal with the file name? It's in your
> tmp folder, which is likely /tmp and the file name starts with
> amazon-search-items-
> 
> Sorry - I didn't realize the file location wasn't being shown

There is no file name and no amazon-search* in /tmp or /var/log. It seems to me that the search doesn't even send any request due to the port being restricted (but I don't know why that is or how I can remedy the situation).
Comment 7 Robby Stephenson 2020-08-15 00:39:28 UTC
> There is no file name and no amazon-search* in /tmp or /var/log. It seems to
> me that the search doesn't even send any request due to the port being
> restricted (but I don't know why that is or how I can remedy the situation).

I found the issue, clearly a bug on my part. Thanks for following up. I'll work on getting a fix in the next release.
Comment 8 frog 2020-08-15 06:26:07 UTC
Oh great! Thanks.
Comment 9 Robby Stephenson 2020-08-21 21:25:53 UTC
Git commit 061742039b8eb5e96e8dfb1af099388cc7eaf84c by Robby Stephenson.
Committed on 21/08/2020 at 21:24.
Pushed by rstephenson into branch 'master'.

Use correct url and sent appropriate HTTP headers for amazon request

Given the fact that I can't make valid requests myself, all I can verify
if that the response codes match up with the Amazon AWS documentation.

FIXED-IN: 3.3.3

M  +4    -0    ChangeLog
M  +27   -18   src/fetch/amazonfetcher.cpp
M  +12   -2    src/fetch/amazonrequest.cpp
M  +1    -0    src/fetch/amazonrequest.h
M  +25   -0    src/tests/amazonfetchertest.cpp
M  +2    -0    src/tests/amazonfetchertest.h

https://invent.kde.org/office/tellico/commit/061742039b8eb5e96e8dfb1af099388cc7eaf84c
Comment 10 Robby Stephenson 2020-08-21 21:26:08 UTC
Git commit 2fbdeb0701c5ee72402a70b4a6c31474127fa0b0 by Robby Stephenson.
Committed on 21/08/2020 at 21:26.
Pushed by rstephenson into branch '3.3'.

Use correct url and sent appropriate HTTP headers for amazon request

Given the fact that I can't make valid requests myself, all I can verify
if that the response codes match up with the Amazon AWS documentation.

FIXED-IN: 3.3.3

M  +4    -0    ChangeLog
M  +27   -18   src/fetch/amazonfetcher.cpp
M  +12   -2    src/fetch/amazonrequest.cpp
M  +1    -0    src/fetch/amazonrequest.h
M  +25   -0    src/tests/amazonfetchertest.cpp
M  +2    -0    src/tests/amazonfetchertest.h

https://invent.kde.org/office/tellico/commit/2fbdeb0701c5ee72402a70b4a6c31474127fa0b0
Comment 11 Robby Stephenson 2020-08-21 21:27:30 UTC
I can't completely verify the fix. Once you can check yourself, please let me know if you get errors, and if so, please share the log file as mentioned previously. Thanks!
Comment 12 frog 2020-10-07 07:50:56 UTC
Sorry that it took me so long to answer but my operating system didn't update tellico for quite some time. 
The reported error seems to be fixed, but I can't tell you for sure because now I get a different error message: "The request has not been correctly signed."
Comment 13 Robby Stephenson 2020-10-11 18:51:52 UTC
(In reply to frog from comment #12)
> Sorry that it took me so long to answer but my operating system didn't
> update tellico for quite some time. 
> The reported error seems to be fixed, but I can't tell you for sure because
> now I get a different error message: "The request has not been correctly
> signed."

Hmmm, I'm not sure what might cause that. I've verified the signing a couple different ways. Is this for the US endpoint for Amazon? Are you able to generate that log file mentioned in comment #3?
Comment 14 frog 2020-10-11 19:11:14 UTC
This is what the log looks like:

{"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":"InvalidSignature","Message":"The request has not been correctly signed. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.com/paapi5/documentation/sending-request.html#signing."}]}

I am not sure what to make of it. Are my keys invalid that I used?

Configuration is for Amazon (US),
Country: United States
Accociate's ID: tellico-20
Comment 15 Robby Stephenson 2020-11-08 18:57:26 UTC
(In reply to frog from comment #14)
> This is what the log looks like:
> 
> {"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":
> "InvalidSignature","Message":"The request has not been correctly signed. If
> you are using an AWS SDK, requests are signed for you automatically;
> otherwise, go to
> https://webservices.amazon.com/paapi5/documentation/sending-request.
> html#signing."}]}
> 
> I am not sure what to make of it. Are my keys invalid that I used?

As you long as you have updated keys for API v5, those should be good. If you didn't mind sharing them with me privately (by email), I could verify Tellico's signature.