1
- """Scrapinghub API Client Library"""
1
+ """
2
+ Scrapinghub API Client Library
3
+ """
2
4
3
5
import os
4
6
import json
5
7
import warnings
6
- import requests
7
- from cStringIO import StringIO
8
-
9
- from requests .compat import urljoin
10
- from requests .models import urlencode
11
8
12
9
13
10
__all__ = ["APIError" , "Connection" ]
11
+ __version__ = '1.0'
14
12
15
13
16
14
class Connection (object ):
@@ -46,13 +44,14 @@ def __init__(self, username_or_apikey=None, password='', _old_passwd='', url='ht
46
44
self .url = url
47
45
self .username_or_apikey = username_or_apikey
48
46
self .auth = (username_or_apikey , password )
49
- self ._request_headers = {'User-Agent' : 'python-scrapinghub/1.0' }
47
+ self ._request_headers = {'User-Agent' : 'python-scrapinghub/{0}' . format ( __version__ ) }
50
48
51
49
def __repr__ (self ):
52
50
return "Connection(%r)" % self .username_or_apikey
53
51
54
52
def _build_url (self , method , format ):
55
53
"""Returns full url for given method and format"""
54
+ from requests .compat import urljoin
56
55
# TODO: verify method's format support
57
56
try :
58
57
base_path = self .API_METHODS [method ]
@@ -64,6 +63,7 @@ def _build_url(self, method, format):
64
63
65
64
def _get (self , method , format , params = None , headers = None , raw = False ):
66
65
"""Performs GET request"""
66
+ from requests .models import urlencode
67
67
url = self ._build_url (method , format )
68
68
if params :
69
69
url = "{0}?{1}" .format (url , urlencode (params , True ))
@@ -84,6 +84,7 @@ def _request(self, url, data, headers, format, raw, files=None):
84
84
85
85
Raises APIError if json response have error status.
86
86
"""
87
+ import requests
87
88
if format not in ('json' , 'jl' ):
88
89
raise APIError ("format must be either json or jl" )
89
90
@@ -282,6 +283,7 @@ def delete(self):
282
283
return result ['count' ]
283
284
284
285
def add_report (self , key , content , content_type = 'text/plain' ):
286
+ from requests .compat import StringIO
285
287
params = {
286
288
'project' : self .project .name ,
287
289
'job' : self .id ,
0 commit comments