I'm using the jira-python client to add a comment to an issue:
issue_id = 'SB-196'
comment = 'A Slack channel has been created for discussing this escalation: slack://channel?id={}&team={}'.format(new_channel_id, SLACK_TEAM_ID)
jira.comment(issue_id, comment)
The jira-python client is just a wrapper around the JIRA rest api. When I execute the code, I get a 404 error from JIRA which is recieving the following URL:
https://jira.mycompany.com/rest/api/2/issue/SB-196/comment/A%20Slack%20channel%20has%20been%20created%20for%20discussing%20this%20escalation:%0Aslack://channel?id=C123456&team=T123456
I'm assuming this is happening because it's trying to encode the Slack URL in the REST URL and getting confused. What's the correct way to encode the including URL so it doesn't get confused? Thanks!
Klaus D. led me down the right path. It turns out jira.comment() does a GET. In order to POST, you have to call jira.add_comment(). Once I did that, all worked fine (the client library automatically did the url encoding).
Related
I am trying to use the python package yagmail to send emails but am having a tough time getting authorization to work.
My issue is getting an Oauth 2 token, but there is a disconnect with yagmail, as specified in a github thread. As stated in this post, https://github.com/kootenpv/yagmail/issues/143, it appears that google does not supply the credential file in the correct format. But I tried a bunch of things and each has its own problem.
When I set up a Client ID in the Google API console, download the
json as credentials.json and let the system create the token.json,
things work to a point: I am brought through google to "pick an
account, do you want to continue" and token is created. I am able to
print labels for the gmail account. But when I issue
yag.send(to='xxx#gmail.com', subject='Testing Yagmail',
contents='Hurray, it worked!'), I get an error "TypeError:
refresh_authorization() got an unexpected keyword argument 'token'."
When I look at the token file, it does contain the key 'token' which
it should not per this github post https://github.com/kootenpv/yagmail/issues/143#issuecomment-527115298][2].
If I go into the token and edit it to reflect the the expected
contents as identified in the above link by removing keys that are
not specified and prefixing the names with 'google_', I get an error
"ValueError: Authorized user info was not in the expected format,
missing fields refresh_token, client_id, client_secret." It doesn't
seem to like the 'google_' prefix.
editing the token file as above without the 'google_' prefix seems to
get further producing a different error "An error occurred:
<HttpError 403 when requesting
https://gmail.googleapis.com/gmail/v1/users/me/labels?alt=json
returned "Request had insufficient authentication scopes"
I am stuck. Relatively new to Oauth2, but it seems others are able to use yagmail. Is there a trick I am missing? I originally posted on Github because I found that other related post, but it seems SO is more geared toward Q&A. Is there a relation betweeen Github and SO? Difference?
Thanks for any assistance,
Brian
I finally found a solution and the answer was hidden in plain sight.
First the Oauth authorization needed to be set up as outlined in this post (which is excellent): Sending email via Gmail & Python
As stated, when yagmail is run the first time the authorization process gives instructions, the final stating to "Navigate to the following URL to auth:" and asks "Enter the localhost URL you were redirected to:"
The problem is the browser window shows what appears to be an error message, a sad face with a message "This site can’t be reached, localhost refused to connect, reload", etc. I never thought this was expected behavior. The url is the one being navigated to in the error screen.
Simply stating the error should be expected, and the url needs to be copied and pasted in the post above would help a lot.
I am testing MSAL and ROPC flow. When I run sample https://github.com/Azure-Samples/ms-identity-python-desktop I get error:
python username_password_sample.py parameters.json
invalid_client
AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
I was having same problem while following MS documentation and used curl. Please check my other question where SO community helped me to solve problem. After adding application registration secret to curl request, I got valid token and I was able to fetch mails.
What is confusing me is fact that secret is not present in parameters.json file.
You missed the step No.6 from this link: https://github.com/Azure-Samples/ms-identity-python-desktop/tree/master/1-Call-MsGraph-WithUsernamePassword
If the application was set as Public Client, then the secret is not required.
For more details, you can read https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc#authorization-request for reference.
i am new to using the TOMTOM API but i got it working with the example in the browser without a problem, call:
https://api.tomtom.com/routing/1/calculateReachableRange/50.97452,5.86605/json/?key=[MYKEY]&timeBudgetInSec=3600
in the browser i get my json response with my polygon point. But in python i just get the error stating:
"Invalid request: should contain one of the following elements 'avoidVignette' or 'allowVignette'"
Does anybody have any idea why it works in the browser but gives an error when i use it in python code?
mycode:
request_post = requests.post('https://api.tomtom.com/routing/1/calculateReachableRange/50.97452,5.86605/json/?key=[MYKEY]&timeBudgetInSec=3600')
thanks in advance
I figured it out with the help of the comment of #ForceBru.
I used postman to figure out what the problem was and it seems that if you do not use the link directly in the browser but use it as a real post request you are needed to give it a xml or json body where you need to specifiy:
{"avoidVignette": []}
if you are using json.
If you put this in your post request as body it should work like a charm.
Working code:
requests.post('https://api.tomtom.com/routing/1/calculateReachableRange/50.97452,5.86605/json/?key=[MYKEY]&timeBudgetInSec=3600', json={"avoidVignette": []})
Hope this helps some people forward if they get the same error.
If You are not providing any POST parameters than You can use GET method.
Here is the link to Online Routing API Explorer - link
Soundclouds API is returning 403 on some tracks for me. I have tried playing with the raw http endpoints and also the soundcloud api wrapper for python, both have the issue.
https://api.soundcloud.com/tracks/251164884.json?client_id=CLIENT_ID
The above one returns a 403 error while below one works, using same CLIENT_ID obviously
https://api.soundcloud.com/tracks/197355235.json?client_id=CLIENT_ID
Using the library wrapper I get. requests.exceptions.HTTPError: 403 Client Error: Forbidden
import soundcloud
client = soundcloud.Client(client_id=CLIENT_ID)
track = client.get('/resolve', url='https://soundcloud.com/mtarecords/my-nu-leng-flava-d-soul-shake')
https://soundcloud.com/calyxteebee/nothing-left
Another track that also doesn't resolve. Not all tracks have this issue, most work how they always have.
If you go to the Share -> Embed on Soundcloud the track_id will be in there, so I know I am using the correct track_id.
Viewing the http endpoints in browser I get the error.
Failed to load resource: the server responded with a status of 401 (Unauthorized) - https://api.soundcloud.com/favicon.ico
Anyone else run into this issue before?
Using your two examples I get valid results for both
Example 1:
https://api.soundcloud.com/resolve?url=https://soundcloud.com/calyxteebee/nothing-left&client_id=CLIENT_ID
returns
https://api.soundcloud.com/tracks/251164884?client_id=CLIENT_ID
Example 2:
https://api.soundcloud.com/resolve?url=https://soundcloud.com/mtarecords/my-nu-leng-flava-d-soul-shake&client_id=CLIENT_ID
returns
https://api.soundcloud.com/tracks/249638630?client_id=CLIENT_ID
using this url, working perfectly sir. Try this. :D
https://api.soundcloud.com/tracks/TRACK_ID/stream?client_id=CLIENT_ID
I have been investigating this issue for some time now, and I discovered something which at least solves my situation, dunno if it will solve yours.
The Revelation:
If you do a head request with curl (-I option) then it seems to always return with a 200/300 range response.
Why it works: I am streaming Soundcloud tracks with URLs like https://api.soundcloud.com/tracks/TRACK_ID/stream?client_id=CLIENT_ID in an iOS app using FreeStreamer. The stream was failing on exactly those tracks for which curl -v returned 403 for the tracks URL (it returns 401 for the stream URL). So to solve my situation, I perform a head request which gives 302 Found, extract the mp3 URL, and I use that to stream instead of the original URL.
I consider this a bug of the library (since it should be able to handle any 302) and I created an issue for it.
When I do a PUT request in RESTClient it works, but it fails in the Postman Chrome extension.
I need to call the Hadoop REST API. When I use curl all is okay, as with RESTClient. It fails when I use Python httplib, as with Postman.
Here is it working in RESTClient:
Here is it failing in Postman:
It returns a java.lang.UnsupportedOperationException with the message op=NULL is not supported.
How can I send this PUT request correctly with Python's httplib? For some reason curl is not suitable here.
It looks like the endpoint you're hitting requires an op argument to be provided in the query string. You have ?op=CREATE in your RESTClient screenshot, but it doesn't appear in your Postman screenshot.
I notice also that in your RESTClient screenshot the server is responding with a redirect to add an additional parameter overwrite=false; you may need to add this parameter to your request in order for the operation to actually be carried out.