Project

General

Profile

« Previous | Next » 

Revision 5106

tnrs.py: tnrs_request(): parse_response(): Include both the response headers and the response body in the InvalidResponse message

View differences:

lib/tnrs.py
56 56

  
57 57
def gwt_encode(str_): return re.sub(r'[^\w.() -]+', r' ', str_)
58 58

  
59
def parse_response(name, pattern, response):
60
    match = re.match(pattern, response)
61
    if not match: raise InvalidResponse('Invalid '+name+' response:\n'+response)
59
def parse_response(name, pattern, str_, response, response_info):
60
    match = re.match(pattern, str_)
61
    if not match:
62
        raise InvalidResponse('Invalid '+name+' response:\n'+response_info+'\n'
63
            +response)
62 64
    return match.groups()
63 65

  
64 66
def tnrs_request(taxons, debug=False):
......
97 99
    request = submission_request_template.replace('[taxons]',
98 100
        r'\\n'.join(map(gwt_encode, taxons))) # double-escape \n
99 101
    response, response_info = do_request(request)
100
    key, = parse_response('submission', submission_response_pattern, response)
102
    key, = parse_response('submission', submission_response_pattern, response,
103
        response, response_info)
101 104
    debug_log('key', key)
102 105
    key_enc = gwt_encode(key)
103 106
    
104 107
    debug_log('Retrieve')
105 108
    request = retrieval_request_template.replace('[key]', key_enc)
106 109
    response, response_info = do_repeated_request(request)
107
    parse_response('retrieval', retrieval_response_pattern, response)
110
    parse_response('retrieval', retrieval_response_pattern, response, response,
111
        response_info)
108 112
    session_id, = parse_response('retrieval info',
109
        retrieval_response_info_pattern, response_info)
113
        retrieval_response_info_pattern, response_info, response, response_info)
110 114
    debug_log('session_id', session_id)
111 115
    headers['Cookie'] = 'JSESSIONID='+session_id
112 116
    
......
117 121
    debug_log('Prepare download')
118 122
    request = download_request_template.replace('[key]', key_enc)
119 123
    response, response_info = do_request(request)
120
    csv_url, = parse_response('download', download_response_pattern, response)
124
    csv_url, = parse_response('download', download_response_pattern, response,
125
        response, response_info)
121 126
    csv_url += download_url_suffix
122 127
    debug_log('csv_url', csv_url)
123 128
    

Also available in: Unified diff