New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for broken PUT methods #414 #415
Fix for broken PUT methods #414 #415
Conversation
This looks OK to me. If I'm correct, the PUT routes require to send data as json, explaining why the id argument needs to be passed a second time, is that right? Although Travis failed on this PR, but it seems it is for different reasons related to pycov, @hugovk would you mind taking a look? |
For one, it's a bit odd the Travis result isn't shown here in the PR. Perhaps the integration needs checking in the repo settings? Sometimes removing it and re-adding helps. Anyway, the CI did run, here's the link: https://travis-ci.org/github/sixohsix/twitter/builds/703358264 It's also failing on master. Will check. |
PR to fix the CI: #416 |
As I follow it, there are only two API calls that use PUT (updating DM welcome message, and hide replies currently in labs) - they both take most of the data within a JSON body, but the both also have an id parameter they are referencing in the url path. If I've followed the existing code assumed if there was a json body then there was no need to pass any parameters in the path (other than OAuth stuff) so ignored them, but that leads to an error about missing id... |
@hugovk Yes indeed this is weird that Travis does not show up in the PRs anymore, but I don't have the rights to touch the repo settings. @sixohsix could you try and reattach Travis? @snail-coupe yeah I got that, this is why I was asking whether both PUT routes require json data. So It sounds like a yes. |
e8bc6af
to
05bc0a4
Compare
Done (I think) - I should have included references for both PUTs - sorry - first timer https://developer.twitter.com/en/docs/direct-messages/welcome-messages/api-reference/update-welcome-message |
Thanks, yes that did the trick edit: a potential solution seems attainable following this trick: https://stackoverflow.com/questions/111945/is-there-any-way-to-do-http-put-in-python/111988#111988 (or here https://stackoverflow.com/questions/111945/is-there-any-way-to-do-http-put-in-python/44781372#44781372 ) |
I didn't even think about other python versions, sorry! My code runs on a raspberry pi which I think is 3.7 but does have 2.7 as well. I'll make sure it works with 2.7, and push again once it does so; those stack overflow links looked useful. |
Sorry for not getting back to this - I've gone with a slightly hacky solution based upon one of those stack overflow answers. Given "our" code always determines the method it wants, just over-ride the get_method function of whichever version of urllib and Request to just use the method we want. I recently needed to use an API call that uses DELETE and this appears to work fine for that as well. |
Hello, |
Thank you! And sorry for missing the other python 2.7 (I did intent to check the Travis output but when I pushed that update it was taking a while to go though and hasn't got back to it) |
Yep, no problem, I understand, Travis is a mess these days and we are on the verge of migrating to github actions. Thanks again for your contribution! |
Pass _method directly to urllib_request to enable PUT requests and also ensure consistency between signature and actual request,.
Pass id parameter into auth.encode_params() for PUT requests, as required by two existing API methods using PUT.