Unable to access Gerrit changes details from python-gerrit-api - python

I am trying to access particular gerrit details based on it's change-id. But unable to get the details.
I have used python-gerrit-api. code snippet as follows
from gerrit import GerritClient
gerrit = GerritClient(base_url="base-url-gerrit", username='xxxxx', password='xxxxxx', ssl_verify=False, cert=None)
change = gerrit.changes.get('123456')
but response getting as "404 Client Error: Not Found for url"
when I try to access same url "https://base-gerrit.com/changes/123456", directly json data is downloading.
Please let me know where did I do wrong, is there any otherway to get the change details based on change-id.

Related

I am getting error when I am retrieving data from firebase

I am posting this question because I haven't found any proper solution related to my problem.
I am trying to retrieve my user's data from Firebase but I am unable to do it. Please explain to me what I am doing wrong.
For this project, I am using Flask API. I also included all required indexes in my rules for the database. My error message accrues on line 106.
Error message:
Code
Json for data
This is a default code required for getting data:
from firebase import firebase
firebase = firebase.FirebaseApplication('Your url of the Real Time Database')
obj = firebase.get('/', None) #NOTE: '/' should be followed by the path in case you have child attributes
print(obj) #You will get a dictionary in return

Authorization error 403 with Twitter API using python [duplicate]

I attempted to run the code below and am getting an error that states:
HTTP Error code: 403: Forbidden: Authentication succeeded but account is not authorized to access this resource.
from searchtweets import ResultStream, gen_rule_payload, load_credentials, collect_results
import requests
premium_search_args = load_credentials("/home/dirname/twitter_keys.yaml",
yaml_key="search_tweets_premium",
env_overwrite=False)
rule = gen_rule_payload("basketball", results_per_call=100) # testing with a sandbox account
print(rule)
from searchtweets import collect_results
tweets = collect_results(rule,
max_results=100,
result_stream_args=premium_search_args)
# print(tweets.all_text)
[print(tweet.all_text, end='\n\n') for tweet in tweets[0:10]];
My YAML file looks like this:
search_tweets_premium:
account_type: premium
endpoint: https://api.twitter.com/1.1/tweets/search/fullarchive/dev.json
consumer_key: AAAAAAAAAAAAAAAAAAAAA
consumer_secret: BBBBBBBBBBBBBBBBBBBBBBBBBBB
Only other thing to note is that I am using the free/sandbox service.
Any ideas if I am doing anything wrong in the code, the YAML, and/or within my Twitter developer account?
You'll need to go to https://developer.twitter.com/en/account/environments
There you should be able to see the various development environments that you have. You can create one should they not have been created.
The dev environment label would then be the thing you use to replace in your endpoint.
In my example, it would be:
https://api.twitter.com/1.1/tweets/search/fullarchive/development.json
If that still doesn't work, you might need to include a bearer token in your YAML file.

Rest api of gerrit gives the response but Python-gerrit-api package for fetching revisions gives status 404

Documentation: https://python-gerrit-api.readthedocs.io/en/latest/
Code
gerrit = GerritClient(base_url="https://gerrit.xx.com",username='xxx',password='xxx')
change = gerrit.changes.get("xxx")
ab=change.get_revision("32423")
print(ab.get_commit().list_change_files())
Question
For some endpoints, I am able to send get responses from the rest api but via this package I get this error(gerrit.utils.exceptions.NotFoundError: 404 Client Error). I am able to get response from Get Rest api for this url: gerrit.xx.xx.com/a/projects/xxxx/commits/xxxx/files via postman. But error with above code.
Looks like this is a bug, I have fixed it and made a pull request. See: https://github.com/shijl0925/python-gerrit-api/pull/5

How to get Salesforce username using REST api?

I am using web server flow for oAuth and simple-salesforce REST api to login the user using the access token and instance url. I have gone through the http://www.salesforce.com/us/developer/docs/api_rest/index.htm documentation and coudn't find anything on it.
Based on your comment saying you're using https://github.com/neworganizing/salesforce-oauth2 : you can do something like :
import urllib
# After you get the code
response = salesforce_oauth_2.get_token(code)
print urllib.urlopen(response['id'])
The json object response returned by get_token should contain an id attribute which is an url that you can query for more information about the current user. See here for more details (paragraph 5).
Get your salesforce dev to write a simple method that when pinged returns the context user details that you're after. See here for an example.

Posting to Facebook App page wall as the App Page in python

I am trying make a post on my apps page wall as if it is coming from the app page (not another user) After researching I seem to find no solution that actually works!
I have tried to follow the documentation here:
I then get my 'access_token_page' by getting it from:
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=CLIENT_SECRET&grant_type=client_credentials
Then using the facebook python api I try:
graph1 = facebook.GraphAPI(access_token_page)
graph1.put_wall_post(fbmessage, attachment, profile_id=APP_PAGE_ID)
However this just returns the following facebook error:
*** GraphAPIError: (#200) The user hasn't authorized the application to perform this action
Any ideas on what I am missing? Remember, I am looking to have the App Page make a post to itself, not have a post be generated from another username.
Thank you!
What you had done is using App Access Token to publish to page.
You should using Page Access Token to post on page admin behalf instead. User Access Token is works too but it's a bug as reported at https://developers.facebook.com/bugs/647340981958249, so it's not recommended to use User Access Token by this time of writing.
As documented at https://developers.facebook.com/docs/reference/api/page/#page_access_tokens:
Page Access Tokens
To perform the following operations as a Page, and not the current
user, you must use the Page's access token, not the user access token
commonly used for reading Graph API objects. This access token can be
retrieved by issuing an HTTP GET to /USER_ID/accounts with the
manage_pages permission.
More info about different type of access token please visit https://developers.facebook.com/docs/facebook-login/access-tokens/
Try Django Facebook:
https://github.com/tschellenbach/Django-facebook
This will deal with many of your API problems.
You need the page access token, see here:
https://developers.facebook.com/docs/facebook-login/access-tokens/
Ask for manage_pages as an extra permission
After getting that setup, simply do:
user_graph = OpenFacebook(user_access_token)
response = user_graph.get('me/accounts')
# turn the response to a dict, and be sure to get the page you want
page_access_token = response['data'][0]['access_token']
graph = OpenFacebook(page_access_token)
graph.set('me/feed', message='helloworld')
You can find more docs here:
http://django-facebook.readthedocs.org/en/latest/open_facebook/api.html

Categories