[p4python] Test code erroring out

Sven Erik Knop sknop at perforce.com
Tue Aug 12 07:44:38 PDT 2008


Hi Matt,

Unfortunately, there is an error in documentation. Here is the correct code:

/from P4 import P4, P4Exception
    p4 = P4()
    p4.port = "port"           #actual port was here, no worries
    p4.user = "username"  #actual user name was here as well/
// 
/    try:
       p4.connect()
       info1 = p4.run("info")
       s = info['serverVersion']
       print s
       p4.disconnect()
    except P4Exception:
       for e in p4.errors:
        print e/

P4Exception is not a member of the instance "p4", but of the module 
"P4". With these changes you should be able to run the code.

Kind regards,

Sven Erik

Matt Fielding (R* New England) wrote:
> I've recently installed the p4python API on top of python 2.5.2 on my 
> machine to try and test out some perforce scripts, but I am running 
> into an issue that I don't quite understand.
>  
> /    Traceback (most recent call last):
>       File "test.py", line 12, in <module>
>         except p4.P4Exception:
>       File "C:\Python25\lib\site-packages\P4.py", line 244, in __getattr__
>         raise AttributeError, name
>     AttributeError: P4Exception/
>  
> This error is coming up while running the following code:
>  
> /    from P4 import P4
>     p4 = P4()
>     p4.port = "port"           #actual port was here, no worries
>     p4.user = "username"  #actual user name was here as well/
> // 
> /    try:
>        p4.connect()
>        info1 = p4.run("info")
>        s = info['serverVersion']
>        print s
>        p4.disconnect()
>     except p4.P4Exception:
>        for e in p4.errors:
>         print e/
> // 
> The code comes straight out of the P4Python manual, and is the first, 
> most basic chunk of code I could possibly run. It appears something is 
> incorrect in my P4.py file, but seeing as I just installed the API, I 
> don't see why something would be messed up already. I'm hoping someone 
> else has run into this problem and has a quick solution for me.
> ------------------------------------------------------------------------
>
> _______________________________________________
> p4python mailing list
> p4python at perforce.com
> http://maillist.perforce.com/mailman/listinfo/p4python
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.perforce.com/pipermail/p4python/attachments/20080812/5ce18277/attachment-0001.html>


More information about the p4python mailing list