Unable to access launchpadlib with authenticated launchpad access

Asked by Swati Sharma

I am able to fetch the launchpad data using login_anonymously to launchpadlib.

Now, I have an account on Launchpad and I want to access launchpadlib data using my credentials of Launchpad.

How, do I get the authenticated access. Any link/example/lines of code, Pls help ??

Question information

Language:
English Edit question
Status:
Solved
For:
Launchpad itself Edit question
Assignee:
No assignee Edit question
Solved by:
William Grant
Solved:
Last query:
Last reply:
Revision history for this message
William Grant (wgrant) said :
#1

You want the login_with method. See https://help.launchpad.net/API/launchpadlib#Authenticated_access for examples.

Revision history for this message
Swati Sharma (swati-shukla1) said :
#2

Hi William,

Thanks for your prompt response.

However, I have already checked this link out and this is not what I am looking for. This link decribes the scenario when I want to have launchpad integrated on my custom website.

I will again explain the problem here-
"I have a launchpad account and bugs assigned to me in eg:openstack project. Now I want to have read-write access on my bugs of openstack."

As an anonymous user, I am able to fetch the details using--
####
from launchpadlib.launchpad import Launchpad
cachedir = "/home/tcs/launchpad_cache/"
launchpad = Launchpad.login_anonymously('just testing', 'production', cachedir, version="devel")
openstack_data = launchpad.projects['openstack']
people = launchpad.people
my_bug = launchpad.people['swati-shukla1']
assigned_tasks = openstack_data.searchTasks(assignee = my_bug)
assigned_bugs = [task.bug for task in assigned_tasks]
print assigned_bugs
####

What if I want to login into launchpad using my credentials and have write access also to my own bugs??

There, this question remains unanwered for me. Kindly help with any suggestions.

Thanks.

Revision history for this message
William Grant (wgrant) said :
#3

The "Authenticated access for website integration" section describes how to integrate it in a website, but the "Authenticated access" section that I linked shows how to do it in a script. Just replace "login_anonymously" with "login_with" in the code you have.

Revision history for this message
Swati Sharma (swati-shukla1) said :
#4

Hi William,

I tried using -
"import sys
    from launchpadlib.launchpad import Launchpad

    def no_credential():
        print "Can't proceed without Launchpad credential."
        sys.exit()

    launchpad = Launchpad.login_with(
        'My Application', 'staging', credential_save_failed=no_credential)"

It gave me error saying ----
"raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.ServerNotFoundError: Unable to find the server at staging.launchpad.net"

Suppose, I want to get write access of launchpad project (eg: horizon) bugs.
The link is https://bugs.launchpad.net/horizon/ . Now I want to login with my launchpad credentials.

What are the steps to do that?? In the answer you provided, how am I providing the launchpad credentials in my code?

Revision history for this message
William Grant (wgrant) said :
#5

In the normal workflow you don't provide your credentials directly. If you're running the script on your local machine, it will print a URL the first time to open in your web browser. That URL lets you authenticate the script to Launchpad, and it will store the credentials in your desktop keyring. Further runs of the script will use the stored credentials and not prompt for them.\

staging.launchpad.net is offline right now due to a hardware fault, so you'll have to wait until it's back up or test carefully against production.

Revision history for this message
Swati Sharma (swati-shukla1) said :
#6

Hi William,

I am back on trying this out. I will share an example with you so that you can understand it better-

I am an authenticated user of launchpad.net. Now I want to login with my launchpad credentials to access this site's data.
I am able to do this as a public user and can login anonymously using-

launchpad = Launchpad.login_anonymously('just testing', 'production', cachedir, version="devel")
people = launchpad.people
swati = people.getByEmail(<email address hidden>")
print swati.display_name

But I am not able to use the 'login_with()' method of the API to login directly with my launchpad credentials and access its data.

Please share any commands if you have in mind for this.

Thanks and Regards.

Revision history for this message
William Grant (wgrant) said :
#7

"But I am not able to use the 'login_with()' method of the API to login directly with my launchpad credentials and access its data."

Why not?

Revision history for this message
Swati Sharma (swati-shukla1) said :
#8

Hi William,

I am checking this- https://help.launchpad.net/API/launchpadlib, and here it is given, for authenticated access it will use -

launchpad = Launchpad.login_with('My Application', 'staging'),

Here, where do I give my launchpad.net username and password to enter into my account and access my profile data??

Thanks in advance.

Revision history for this message
William Grant (wgrant) said :
#9

launchpadlib uses OAuth to authenticate, not your username and password directly. login_with prints a URL that you need to visit in your web browser, using your Launchpad cookie or email address and password to authorize launchpadlib's OAuth token to access your Launchpad account.

Revision history for this message
Swati Sharma (swati-shukla1) said :
#10

Hi William,

Thanks for your responses.

I tried this-

from launchpadlib.credentials import Credentials
credentials = Credentials("my website")
request_token_info = credentials.get_request_token(web_root="production")

but everytime when I use "staging" or "production", I get the same error-
httplib2.ServerNotFoundError: Unable to find the server at staging.launchpad.net
OR
httplib2.ServerNotFoundError: Unable to find the server at launchpad.net

Is there a problem in generating a token for the site, or there is a downtime currently??

Revision history for this message
William Grant (wgrant) said :
#11

>>> c = Credentials("foo")
>>> rt = c.get_request_token(web_root="production")
>>> rt
u'https://launchpad.net/+authorize-token?oauth_token=<REDACTED>'

Are you sure that machine has network access and DNS configured correctly?

Revision history for this message
Swati Sharma (swati-shukla1) said :
#12

Thanks William, it worked out when I tried on another system.

Now, when I proceed to -

exchange_request_token_for_access_token() and it successfully executes, an authorized access token will be present in credentials.access_token. Then, we can then pass the Credentials object into the Launchpad constructor.

launchpad = Launchpad(credentials, service_root="production")

Here, we are again getting the error 'Type Error: __init__() Takes atleast 4 arguments(3 given)'...

Then if I try launchpad = Launchpad(credentials, service_root="production", "devel"), it again says 'Type Error: __init__() Takes atleast 4 arguments(4 given)'...

I was also going through some other chat of 2013, where it was mentioned that the Launchpad API has changed now, but the people have not changed their documentation. And now, if people request the Launchpad developers for Launchpad SSO, then they grant access........ Is this true?? What should be my next step to get this working??

Revision history for this message
William Grant (wgrant) said :
#13

On 22/04/15 08:06, Swati Sharma wrote:
> Question #262376 on Launchpad itself changed:
> https://answers.launchpad.net/launchpad/+question/262376
>
> Status: Needs information => Open
>
> Swati Sharma gave more information on the question:
> Thanks William, it worked out when I tried on another system.
>
> Now, when I proceed to -
>
> exchange_request_token_for_access_token() and it successfully executes,
> an authorized access token will be present in credentials.access_token.
> Then, we can then pass the Credentials object into the Launchpad
> constructor.
>
> launchpad = Launchpad(credentials, service_root="production")
>
>
> Here, we are again getting the error 'Type Error: __init__() Takes atleast 4 arguments(3 given)'...
>
> Then if I try launchpad = Launchpad(credentials,
> service_root="production", "devel"), it again says 'Type Error:
> __init__() Takes atleast 4 arguments(4 given)'...

>>> c = Credentials("foo")
>>> c.get_request_token(web_root="production")
u'https://launchpad.net/+authorize-token?oauth_token=<REDACTED>'
>>> # Authorise access using web browser.
>>> c.exchange_request_token_for_access_token(web_root='production')
>>> lp = Launchpad(c, None, None, service_root='production')
>>> lp.me
<person at https://api.launchpad.net/1.0/~wgrant>

> I was also going through some other chat of 2013, where it was mentioned
> that the Launchpad API has changed now, but the people have not changed
> their documentation. And now, if people request the Launchpad developers
> for Launchpad SSO, then they grant access........ Is this true?? What
> should be my next step to get this working??

I don't understand what you mean about SSO.

Revision history for this message
Swati Sharma (swati-shukla1) said :
#14

Hi William,

SSO means Launchpad single sign-on. I was able to do the steps that you suggested and access my profile details.

Currently, "Website integration" steps are successfully running, where once the user logs in first time and he visits the URL, he is able to login later using the desktop keyring credentials.

Now, I am using my "Mobile application" coded in Android, and I want to try out the same thing thing of logging in launchpad. How will it get the URL and store the keyring in this scenario?

Revision history for this message
Best William Grant (wgrant) said :
#15

launchpadlib just provides the URL and the methods that you have to call. It's up to your application to interact with the user.

Revision history for this message
Swati Sharma (swati-shukla1) said :
#16

Thanks William Grant, that solved my question.