How do you print a function that returns a request in Python?
<p>I have a function that gets the profile data of an user:</p>

<p><strong>API.py</strong></p>

<pre><code>def getProfileData(self):
    data = json.dumps({
    '_uuid'        : self.uuid,
    '_uid'         : self.username_id,
    '_csrftoken'   : self.token
    })
    return self.SendRequest('accounts/current_user/?edit=true', self.generateSignature(data))
</code></pre>

<p>I want to print the returned request in the terminal, so I did this:</p>

<p><strong>test.py</strong></p>

<pre><code>from API import API

API = API("username", "password")
API.login() # login
print(API.getProfileData())
</code></pre>

<p>But nothing is logged in the console.</p>

<p>Maybe I'm doing it the JavaScript way, since that's my background.</p>

<p>What's the correct way to do it?</p>

<p><strong>EDIT:</strong></p>

<p>This is what's inside <code>SendRequest</code>:</p>

<pre><code>def SendRequest(self, endpoint, post = None, login = False):
        if (not self.isLoggedIn and not login):
            raise Exception("Not logged in!\n")
            return;

        self.s.headers.update ({'Connection' : 'close',
                                'Accept' : '*/*',
                                'Content-type' : 'application/x-www-form-urlencoded; charset=UTF-8',
                                'Cookie2' : '$Version=1',
                                'Accept-Language' : 'en-US',
                                'User-Agent' : self.USER_AGENT})

        if (post != None): # POST
            response = self.s.post(self.API_URL + endpoint, data=post) # , verify=False
        else: # GET
            response = self.s.get(self.API_URL + endpoint) # , verify=False

        if response.status_code == 200:
            self.LastResponse = response
            self.LastJson = json.loads(response.text)
            return True
        else:
            print ("Request return " + str(response.status_code) + " error!")
            # for debugging
            try:
                self.LastResponse = response
                self.LastJson = json.loads(response.text)
            except:
                pass
            return False

    def getTotalFollowers(self,usernameId):
        followers = []
        next_max_id = ''
        while 1:
            self.getUserFollowers(usernameId,next_max_id)
            temp = self.LastJson

            for item in temp["users"]:
                followers.append(item)

            if temp["big_list"] == False:
                return followers            
            next_max_id = temp["next_max_id"]         

    def getTotalFollowings(self,usernameId):
        followers = []
        next_max_id = ''
        while 1:
            self.getUserFollowings(usernameId,next_max_id)
            temp = self.LastJson

            for item in temp["users"]:
                followers.append(item)

            if temp["big_list"] == False:
                return followers            
            next_max_id = temp["next_max_id"] 

    def getTotalUserFeed(self, usernameId, minTimestamp = None):
        user_feed = []
        next_max_id = ''
        while 1:
            self.getUserFeed(usernameId, next_max_id, minTimestamp)
            temp = self.LastJson
            for item in temp["items"]:
                user_feed.append(item)
            if temp["more_available"] == False:
                return user_feed
            next_max_id = temp["next_max_id"]
</code></pre>

<p>If all you want to do is print the response that you get back, you can do that in <code>SendRequest</code>, but I suspect tha tyour real problem is that you are self-serializing your post data when <code>requests</code> does that for you.  In any case, since your question is about printing:</p>

<pre><code>    if response.status_code == 200:
        print('Yay, my response was: %s' % response.content)
        self.LastResponse = response
        self.LastJson = json.loads(response.text)
        return True
    else:
        print ("Request return " + str(response.status_code) + " error!")
        # for debugging
        try:
            self.LastResponse = response
            self.LastJson = json.loads(response.text)
        except:
            pass
        return False
</code></pre>

python