Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
RFE: Make headers available from API calls?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Johnson Earls  
View profile  
 More options Jul 23 2010, 9:20 am
From: Johnson Earls <darkfoxpr...@gmail.com>
Date: Fri, 23 Jul 2010 06:20:26 -0700 (PDT)
Local: Fri, Jul 23 2010 9:20 am
Subject: RFE: Make headers available from API calls?
Hello,

Perhaps this is already available somewhere and I just missed it in
the code.

I'm looking for a way to see the headers that Twitter sends back with
its response.

In particular, Twitter sends back X-RateLimit-* headers that would be
nice to see, as opposed to having to go back and send another
rate_limit_status request.

I've made a patch for my own copy of tweepy, which stores the headers
in the API object; however, I'm not sure if this model would work in
general, as it's not going to be thread-safe (and I'm not sure if the
rest of tweepy is threadsafe or not).

In any case, here's my patch for this.

--- api.py.ORIG 2010-07-23 06:01:01.205377000 -0700
+++ api.py      2010-07-23 06:04:45.805750000 -0700
@@ -30,6 +30,7 @@
         self.retry_delay = retry_delay
         self.retry_errors = retry_errors
         self.parser = parser or ModelParser()
+        self._headers = {}

     """ statuses/public_timeline """
     public_timeline = bind_api(
@@ -692,6 +693,18 @@
         allowed_param = ['id']
     )

+    """ Return the first value of a header received from the last API
call. Return None if no such header. """
+    def header(self, header):
+      if self._headers.has_key(header):
+        return self._headers[header][0]
+      return None
+
+    """ Return the list of values of a header received from the last
API call. Return None if no such header. """
+    def headers(self, header):
+      if self._headers.has_key(header):
+        return self._headers[header]
+      return None
+
     """ Internal use only """
     @staticmethod
     def _pack_image(filename, max_size):

--- binder.py.ORIG      2010-06-15 23:48:38.000000000 -0700
+++ binder.py   2010-07-23 06:00:07.192910000 -0700
@@ -117,6 +117,7 @@
                             result._api = self.api
                     else:
                         cache_result._api = self.api
+                    self.api._headers = {} # headers are invalid
after cache!
                     return cache_result

             # Continue attempting request until successful
@@ -165,6 +166,13 @@

             # Parse the response payload
             result = self.api.parser.parse(self, resp.read())
+            headers = {}
+            for (header,value) in resp.getheaders():
+              if headers.has_key(header):
+                headers[header] = headers[header] + (value,)
+              else:
+                headers[header] = (value,)
+            self.api._headers = headers

             conn.close()


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
inactivist  
View profile  
 More options Aug 27 2012, 8:47 pm
From: inactivist <inactiv...@gmail.com>
Date: Mon, 27 Aug 2012 17:47:04 -0700 (PDT)
Local: Mon, Aug 27 2012 8:47 pm
Subject: Re: RFE: Make headers available from API calls?

*bump*

I'd like to know if this is possible as well.  Specifically, when using the
GET search API.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
inactivist  
View profile  
 More options Aug 27 2012, 9:38 pm
From: inactivist <inactiv...@gmail.com>
Date: Mon, 27 Aug 2012 18:38:58 -0700 (PDT)
Local: Mon, Aug 27 2012 9:38 pm
Subject: Re: RFE: Make headers available from API calls?

And, after further digging, it appears that the GET search API does not
return these headers.  They are only available in the streaming or other
APIs linked to an account/application if I'm interpreting the materials
correctly.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »