Skip to content

Commit

Permalink
timeout please
Browse files Browse the repository at this point in the history
  • Loading branch information
Visgean committed Jul 17, 2012
1 parent 2f697fe commit f8f05f9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _encode_multipart_form(self, fields):
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body

def request(self, path, args=None, post_args=None, raw_url = False):
def request(self, path, args=None, post_args=None, raw_url = False, timeout = 3):
"""Fetches the given path in the Graph API.
We translate args to a valid query string. If post_args is given,
Expand All @@ -255,9 +255,9 @@ def request(self, path, args=None, post_args=None, raw_url = False):
post_data = None if post_args is None else urllib.urlencode(post_args)
try:
if raw_url:
file = urllib2.urlopen(path)
file = urllib2.urlopen(path, timeout = timeout)
else:
file = urllib2.urlopen("https://graph.facebook.com/" + path + "?" + urllib.urlencode(args), post_data)
file = urllib2.urlopen("https://graph.facebook.com/" + path + "?" + urllib.urlencode(args), post_data, timeout)

except urllib2.HTTPError, e:
response = _parse_json(e.read())
Expand Down Expand Up @@ -315,7 +315,7 @@ def api_request(self, path, args=None, post_args=None):
raise GraphAPIError(response)
return response

def fql(self, query, args=None, post_args=None):
def fql(self, query, args=None, post_args=None, timeout = 3):
"""FQL query.
Two reasons to have this method:
1. Graph api does not expose some info fields of a user, e.g.
Expand Down Expand Up @@ -347,7 +347,7 @@ def fql(self, query, args=None, post_args=None):

file = urllib2.urlopen("https://api.facebook.com/method/" +
fql_method + "?" + urllib.urlencode(args),
post_data)
post_data, timeout)
try:
content = file.read()
response = _parse_json(content)
Expand Down

0 comments on commit f8f05f9

Please sign in to comment.