astropy/astroquery — pull request #388 by keflavich (2014-08-09 10:14:29+00:00)
Title: Unable to run sample code on Py3K; Many test failures

Running the first example code in http://astroquery.readthedocs.org/en/latest/ doesn't appear to work in my Python3 installations. It's a standard bytes-vs-strings porting issue, but it seems to affect more then just Simbad. This is with the last 0.2rc release.

The bug stems from `response` (in utils/commons.py's `send_request` method) having a `.content` attribute of bytes in Python3. This presents a problem for `SimbadResult`'s `__split_sections` method's use of regex. I started to prepare a pull request decoding `response.content` in `send_request` if needed, but I think it would involve using some of the private API of `requests.Response`.

A verbose test run (with 47 failures) is at http://astro1.panet.utoledo.edu/~jbooker/astroquery-log
For comparision, a python2 test run with four failures is at http://astro1.panet.utoledo.edu/~jbooker/astroquery-python2-log (includes other bugs)

Below is the output of running the example code in different versions of Python.
```
$ python3.4 -c 'from astroquery.simbad import Simbad; Simbad.query_object("m1")'
Traceback (most recent call last):
File "/usr/lib64/python3.4/site-packages/astroquery/simbad/core.py", line 725, in _parse_result
self.last_parsed_result = resultclass(result.content, verbose=verbose)
File "/usr/lib64/python3.4/site-packages/astroquery/simbad/core.py", line 884, in __init__
SimbadResult.__init__(self, txt, verbose=verbose)
File "/usr/lib64/python3.4/site-packages/astroquery/simbad/core.py", line 809, in __init__
self.__split_sections()
File "/usr/lib64/python3.4/site-packages/astroquery/simbad/core.py", line 816, in __split_sections
section, self.__txt)
File "/usr/lib64/python3.4/re.py", line 166, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python3.4/site-packages/astroquery/simbad/core.py", line 344, in query_object
return self._parse_result(result, SimbadVOTableResult, verbose=verbose)
File "/usr/lib64/python3.4/site-packages/astroquery/simbad/core.py", line 736, in _parse_result
"Exception: " + str(ex))
astroquery.exceptions.TableParseError: Failed to parse SIMBAD result! The raw response can be found in self.last_response, and the error in self.last_table_parse_error. The attempted parsed result is in self.last_parsed_result.
Exception: can't use a string pattern on a bytes-like object
$ python3.3 -c 'from astroquery.simbad import Simbad; Simbad.query_object("m1")'
Traceback (most recent call last):
File "/usr/lib64/python3.3/site-packages/astroquery/simbad/core.py", line 725, in _parse_result
self.last_parsed_result = resultclass(result.content, verbose=verbose)
File "/usr/lib64/python3.3/site-packages/astroquery/simbad/core.py", line 884, in __init__
SimbadResult.__init__(self, txt, verbose=verbose)
File "/usr/lib64/python3.3/site-packages/astroquery/simbad/core.py", line 809, in __init__
self.__split_sections()
File "/usr/lib64/python3.3/site-packages/astroquery/simbad/core.py", line 816, in __split_sections
section, self.__txt)
File "/usr/lib64/python3.3/re.py", line 161, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python3.3/site-packages/astroquery/simbad/core.py", line 344, in query_object
return self._parse_result(result, SimbadVOTableResult, verbose=verbose)
File "/usr/lib64/python3.3/site-packages/astroquery/simbad/core.py", line 736, in _parse_result
"Exception: " + str(ex))
astroquery.exceptions.TableParseError: Failed to parse SIMBAD result! The raw response can be found in self.last_response, and the error in self.last_table_parse_error. The attempted parsed result is in self.last_parsed_result.
Exception: can't use a string pattern on a bytes-like object
$ python2.7 -c 'from astroquery.simbad import Simbad; print(Simbad.query_object("m1"))'
/usr/lib64/python2.7/site-packages/numpy/ma/core.py:3847: UserWarning: Warning: converting a masked element to nan.
warnings.warn("Warning: converting a masked element to nan.")
MAIN_ID RA DEC RA_PREC DEC_PREC COO_ERR_MAJA COO_ERR_MINA COO_ERR_ANGLE COO_QUAL COO_WAVELENGTH COO_BIBCODE
"h:m:s" "d:m:s" mas mas deg
------- ----------- ----------- ------- -------- ------------ ------------ ------------- -------- -------------- -------------------
M 1 05 34 31.94 +22 00 52.2 6 6 nan nan 0 C R 2011A&A...533A..10L
```