Jump to content


P4python Reuse Ticket Based Login

p4python ticket login ticket_file

  • Please log in to reply
3 replies to this topic

#1 Sdaniels

Sdaniels

    Member

  • Members
  • PipPip
  • 10 posts

Posted 31 March 2014 - 11:50 AM

Hello everybody, we are currently switching from security level 1 to 3. (as preparation before switching to 4)

We had some scripts using the P4PASSWD environment variable to login.
With security level 3 we have only ticket based login. What I know, when I do a p4 login on the command line a p4tickets.txt file is updated in the %USERPROFILE% directory.

Now my question is, whether it is possible to update my P4Python scripting to reuse the login information from this file.
A P4() connection object has the attribute ticket_file referencing the correct location but it looks as if this file isn't used.

I'm always forced to do the login 'manually', by assigning the password attribute to the P4() instance. Otherwise the run_login() method fails.

Has someone an advice how to achieve automatic login from p4python without asking the user or storing the password somewhere else?

How does P4V achieve this without asking the user?

Thanks in advance

#2 P4Matt

P4Matt

    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 31 March 2014 - 09:22 PM

Is your P4Python tool running under the system user in both cases? A lot of times I see people run their scripts and such as a different system user; root instead of their normal account. The tickets file is stored in the user home dir, so if you run the script as root it won't see your tickets file.

My usual trick is to use the '-p' flag on login to get a copy of the ticket and store the value myself. You can then 'p4.password' to the ticket value and everything should work.

#3 Sdaniels

Sdaniels

    Member

  • Members
  • PipPip
  • 10 posts

Posted 01 April 2014 - 04:31 AM

Hi P4Matt, thanks for the reply.

Yes, the scripting is running as the same user not as system or root. As I said in my first post, the attribute ticket_file is referencing the proper location %USERPROFILE%\p4tickets.txt .

I've checked the login -p function. Thanks for this hint. This should work.

To get a clear understanding. Is my observation correct, that the p4 login via p4python doesn't provide a way to access the data, stored in the p4tickets file?


Edit:
I'm sorry, but the recommended workaround to use the return value of login -p doesn't seem to work.

>>> p4 = P4()
>>> p4.user = 'Sdaniels'
>>> p4.password = 'mypasswd'
>>> p4.connect()
>>> key = p4.run_login('-p')[0]
>>> p4.password = key
>>> p4.run_login()
... [Error]: 'Password invalid.'


#4 Sdaniels

Sdaniels

    Member

  • Members
  • PipPip
  • 10 posts

Posted 01 April 2014 - 10:18 AM

 Sdaniels, on 01 April 2014 - 04:31 AM, said:

I'm sorry, but the recommended workaround to use the return value of login -p doesn't seem to work.

>>> p4 = P4()
>>> p4.user = 'Sdaniels'
>>> p4.password = 'mypasswd'
>>> p4.connect()
>>> key = p4.run_login('-p')[0]
>>> p4.password = key
>>> p4.run_login()
... [Error]: 'Password invalid.'


OK, I found the answer myself by reading the help description for p4 login. I could use the returned hash key as -P option for all other p4 commands (e.g. p4 -P<key> depots ). But I could of course not use this key to login again :rolleyes:

I can work with this solution. Thank you.





Also tagged with one or more of these keywords: p4python, ticket, login, ticket_file

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users