Jump to content

P4Python Usage Question


  • Please log in to reply
1 reply to this topic

#1 SamAtEdmunds



  • Members
  • Pip
  • 1 posts

Posted 30 August 2013 - 05:37 PM

I installed P4Python on my Mac (10.8) and everything seems fine. The module imports correctly at least. However, when using it I am stuck. Below is my test script:

from P4 import P4,P4Exception	# Import the module

p4 = P4()						# Create the P4 instance
p4.client = "something"
p4.host = "foo.bar.bang.com"
p4.password = "password1"
p4.port = "1234"
p4.user = "something"
p4.exception_level = 2

print p4.connect

try:							 # Catch exceptions with try/except
  p4.connect()				   # Connect to the Perforce Server
  print "Connected"
  info = p4.run("info")		  # Run "p4 info" (returns a dict)
  for key in info[0]:			# and display all key-value pairs
	print key, "=", info[0][key]

except P4Exception, ex:
  print ex

I get to the exception which reads:

[P4.connect()] Connect to server failed; check $P4PORT.
TCP connect to 1234 failed.
connect: Connection refused

So it seems the connection being attempted is to localhost instead of "foo.bar.bang.com". Any help would be greatly appreciated. I am new to Perforce so I am unsure of all the variables at play.

#2 P4Matt


    Advanced Member

  • Members
  • PipPipPip
  • 1383 posts

Posted 30 August 2013 - 07:53 PM

P4PORT is a bit mislead of a name; it's both the hostname and the port of the server you want to talk to. P4HOST is used to override the hostname of the machine you are running on. In your case just set:

p4.port = "foo.bar.bang.com:1234"

And you'll be good.

Also tagged with one or more of these keywords: p4python

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users