Jump to content


Perforce password (P4PASSWD) invalid or unset when using p4python

p4python python login

  • Please log in to reply
2 replies to this topic

#1 mobileben

mobileben

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 18 February 2019 - 05:55 AM

I'm using p4python for an automated build script. This script builds art assets, so it is a long running process (it can take 6-12 hours overall). As it processes artwork, it will either add or edit files with in Perforce. And in the end it will submit the CL. Given the overall duration of the process, the 12 hour ticket has been known to expire. Currently this is running on my machine, but I plan on migrating it to Jenkins soon. I getting ready for this transition, I added support to login if the ticket has expired. I've encountered some odd behavior.

The documentation around this as well as other people with similar issues doesn't seem to correspond to what I'm seeing.

I should note that prior to adjusting the script to login, I was manually logging into Perforce either through a bash shell or p4v (I'm on a Mac) prior to running the script. Usually it can finish in time, but I have encountered times when it has not.

My first pass was to setup the password in the P4 object as follows.

p4.host = p4_config.host
p4.port = p4_config.port
p4.user = p4_config.user
if p4_config.password:
    p4.password = p4_config.password
p4.client = p4_config.client

p4.connect()


and then later call p4.run_login()

What I determined was that this would log me in, however any other subsequent Perforce call within the Python script would result in:

[Error]: 'Perforce password (PASSWD) invalid or unset'

For example, even this would cause the problem.
results = p4.run_login('-s')

Note that from my shell, I could execute any p4 command I wanted, because I was logged in. And if I relaunched the script, the problem would still occur. When a re-ran the script, it is not logging into Perforce (ie. calling run_login). but it is still populating p4.password. This seems like this source of the problem.

What I have discovered was that the safer approach seems to be to never populate p4.password

p4.host = p4_config.host
p4.port = p4_config.port
p4.user = p4_config.user
#if p4_config.password:
#    p4.password = p4_config.password
p4.client = p4_config.client

p4.connect()


and to call run_login explicitly with the password like the following:

results = p4.run_login(password=p4_config.password)


Then it works no problem. I can force logout while the script is running and it can recover properly.

Is this the expected behavior? The documentation provided (https://www.perforce...rogramming.html) really doesn't do a very good job in documenting logging in. I get that it is "simple" in theory. But if you google logging into Perforce via p4python you do actually find a few questions  ... most of which have no real/definitive answer.

As an FYI, I'm using Python 3.7 and version 2018.2.1743033 of p4python

#2 P4JoelK

P4JoelK

    Member

  • Staff Moderators
  • 15 posts

Posted 19 February 2019 - 04:19 AM

Hi Ben, I approved your post. Not sure why that was needed.
The "security" setting matters, I think.  I think p4.password is like setting P4PASSWD, which can't be use at security=3. The ticket hash can be though.

https://www.perforce.../DB5-49899.html

#3 mobileben

mobileben

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 19 February 2019 - 04:49 AM

Joel, Thanks for approving. I did come across a couple of postings in the About the Forums section where a couple of people inquire about approval of postings (granted they are from early 2018).

I'm using Assembla to host Perforce, so I'd have to see what security setting they are using (when I try 'p4 configure show security' it states I don't have permissions for the operation).

I guess I'll work on the assumption that what I am doing is "correct" solely based on it works. Hopefully the documentation around this could be improved. It's pretty vague about this, although I read a SO posting where one person act replied indicated it was very clear, but I didn't see the clarity they stated existed. There are only 2 sections which refer to p4.password: "Logging into Perforce using ticket-based authentication" and "Changing your password". And in both cases they indicate password versus ticket as the value to set.

Anyways, thanks again for the approval and your help.





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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users