Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - object attribute assignment fails
    primarykey
    data
    text
    <p><strong>My question is</strong>, after this line: <code>-&gt; self.__serverUrl = serverUrl</code></p> <p>Why is this the case?: <code>*** AttributeError: Client instance has no attribute '__serverUrl'</code></p> <p><strong>Details</strong></p> <p>I'm using Beatbox to interact with Salesforce and I was getting an error </p> <p><code>*** AttributeError: Client instance has no attribute '_Client__serverUrl'</code></p> <p>I wondered why this field was being accessed before it was set, so I added <code>pdb.set_trace()</code> thinking I could find some answers. This is what I saw (note line 67):</p> <pre><code>(Pdb) --Call-- &gt; /app/env/local/lib/python2.7/site-packages/beatbox/_beatbox.py(65)useSession() -&gt; def useSession(self, sessionId, serverUrl): (Pdb) l 64 # initialize from an existing sessionId &amp; serverUrl, useful if we're being launched via a custom link 65 -&gt; def useSession(self, sessionId, serverUrl): 66 self.sessionId = sessionId 67 self.__serverUrl = serverUrl 68 (scheme, host, path, params, query, frag) = urlparse(self.__serverUrl) 69 self.__conn = makeConnection(scheme, host) 70 </code></pre> <p>I check the value of serverUrl, and all is as it should be. Then I get to line 67, let it execute and think that the value of <code>serverUrl</code> would be in <code>self.__serverUrl</code>. Apparently not....</p> <pre><code>&gt; /app/env/local/lib/python2.7/site-packages/beatbox/_beatbox.py(67)useSession() -&gt; self.__serverUrl = serverUrl (Pdb) n &gt; /app/env/local/lib/python2.7/site-packages/beatbox/_beatbox.py(68)useSession() -&gt; (scheme, host, path, params, query, frag) = urlparse(self.__serverUrl) (Pdb) self.__serverUrl *** AttributeError: Client instance has no attribute '__serverUrl' </code></pre> <p>What is happening here!? This shouldn't be happening. It looks like the assignment is just quietly failing. Why is this value not being assigned here? </p> <p><strong>The Source</strong></p> <p>The source code I'm working with is <a href="http://code.google.com/p/salesforce-beatbox/source/browse/" rel="nofollow">here</a></p> <p>I create a beatbox client and login</p> <pre><code>svc = PythonClient() svc.login(username, password) </code></pre> <p>This calls the login method of python_client.Client. python_client.Client.login calls the login method of it's superclass _beatbox.Client, which looks like this:</p> <pre><code>class Client: def __init__(self, serverUrl=None): ... # login, the serverUrl and sessionId are automatically handled, returns the loginResult structure def login(self, username, password): lr = LoginRequest(self.serverUrl, username, password).post() self.useSession(str(lr[_tPartnerNS.sessionId]), str(lr[_tPartnerNS.serverUrl])) return lr # initialize from an existing sessionId &amp; serverUrl, useful if we're being launched via a custom link def useSession(self, sessionId, serverUrl): self.sessionId = sessionId self.__serverUrl = serverUrl (scheme, host, path, params, query, frag) = urlparse(self.__serverUrl) self.__conn = makeConnection(scheme, host) </code></pre> <p>The assginment happens in _beatbox.Client.useSession, which is the superclass of the object <code>svc</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload