basic get request works
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 3127a34 · Browse files · 1 file·+70 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+70 added−9 removed
- other:+70 added−9 removed
Provenance
- Commit
aa5e477- Tree
43433fe- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
3127a34
1 file changed+70 added−9 removed
modified:requests/models.py+70 added-9 removed
14 unmodified lines15 from urllib2 import HTTPError16 from urlparse import urlparse, urlunparse, urljoin17 from datetime import datetime18 19+20+from .packages import urllib321+print dir(urllib3)22+23 from .config import settings24 from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler25 from .structures import CaseInsensitiveDict22-from .packages.poster.encode import multipart_encode23-from .packages.poster.streaminghttp import register_openers, get_handlers26+# from .packages.poster.encode import multipart_encode27+# from .packages.poster.streaminghttp import register_openers, get_handlers28 from .utils import dict_from_cookiejar, get_unicode_from_response, stream_decode_response_unicode, decode_gzip, stream_decode_gzip29 from .status_codes import codes30 from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, TooManyRedirects31 153 unmodified lines185 186 def build(resp):187 188 response = Response()185- response.status_code = getattr(resp, 'code', None)189+ response.status_code = getattr(resp, 'status', None)190 191 try:188- response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))189- response.fo = resp192+ response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))193+ # response.fo = resp194 191- if self.cookiejar:195+ # if self.cookiejar:196 193- response.cookies = dict_from_cookiejar(self.cookiejar)197+ # response.cookies = dict_from_cookiejar(self.cookiejar)198 195-199 except AttributeError:200 pass201 202 if is_error:15 unmodified lines218 ((r.status_code is codes.see_other) or219 (self.allow_redirects))220 ):221 219- r.fo.close()222+ # r.fo.close()223 224 if not len(history) < settings.max_redirects:225 raise TooManyRedirects()226 77 unmodified lines304 return self.url305 306 307 def send(self, anyway=False):308+ """Sends the shit."""309+310+ # Safety check.311+ self._checks()312+313+ # Build the final URL.314+ url = self._build_url()315+316+ # Setup Files.317+ # Setup form data.318+ #319+ # def urlopen(self, method, url, body=None, headers=None, retries=3,320+ # redirect=True, assert_same_host=True):321+ # req = _Request(url, data=self._enc_data, method=self.method)322+323+324+ if not self.sent or anyway:325+326+ try:327+328+ pool = urllib3.connection_from_url(url, timeout=self.timeout)329+330+ r = pool.urlopen(331+ method=self.method,332+ url=url,333+ body=self.data,334+ headers=self.headers,335+ redirect=False,336+ assert_same_host=False337+ )338+339+ r.socket = pool._get_conn().sock340+341+ # if self.cookiejar is not None:342+ # self.cookiejar.extract_cookies(resp, req)343+344+ # except (urllib2.HTTPError, urllib2.URLError), why:345+ except Exception, why:346+ # if hasattr(why, 'reason'):347+ # if isinstance(why.reason, socket.timeout):348+ # why = Timeout(why)349+350+ # self._build_response(why, is_error=True)351+ print 'FUCK'352+ print why353+354+ else:355+ self._build_response(r)356+ self.response.ok = True357+358+359+ self.sent = self.response.ok360+361+ return self.sent362+363+364+365+ def old_send(self, anyway=False):366 """Sends the request. Returns True of successful, false if not.367 If there was an HTTPError during transmission,368 self.response.status_code will contain the HTTPError code.369 371 unmodified lines