|
33 | 33 | __all__ = ['AstrometryNet', 'AstrometryNetClass']
|
34 | 34 |
|
35 | 35 |
|
| 36 | +MISSING_API_KEY = """ |
| 37 | +Astrometry.net API key not set. You should either set this in the astroquery configuration file using: |
| 38 | +
|
| 39 | + [astrometry_net] |
| 40 | + api_key = qwdqwjnoi12ioj |
| 41 | +
|
| 42 | +or you can set it for this session only using the ``conf`` object: |
| 43 | +
|
| 44 | + from astroquery.astrometry_net import conf |
| 45 | + conf.api_key = 'qwdqwjnoi12ioj' |
| 46 | +
|
| 47 | +or using the ``api_key`` property on the ``AstrometryNet`` class: |
| 48 | +
|
| 49 | + from astroquery.astrometry_net import AstrometryNet |
| 50 | + AstrometryNet.api_key = 'qwdqwjnoi12ioj' |
| 51 | +""".lstrip() |
| 52 | + |
| 53 | + |
36 | 54 | @async_to_sync
|
37 | 55 | class AstrometryNetClass(BaseQuery):
|
38 | 56 | """
|
@@ -71,7 +89,7 @@ class AstrometryNetClass(BaseQuery):
|
71 | 89 | def api_key(self):
|
72 | 90 | """ Return the Astrometry.net API key. """
|
73 | 91 | if not conf.api_key:
|
74 |
| - log.error("Astrometry.net API key not in configuration file") |
| 92 | + raise RuntimeError(MISSING_API_KEY) |
75 | 93 | return conf.api_key
|
76 | 94 |
|
77 | 95 | @api_key.setter
|
@@ -103,18 +121,10 @@ def show_allowed_settings(self):
|
103 | 121 | values=key_info['allowed']))
|
104 | 122 |
|
105 | 123 | def __init__(self):
|
106 |
| - """ Show a warning message if the API key is not in the configuration file. """ |
107 | 124 | super().__init__()
|
108 |
| - if not conf.api_key: |
109 |
| - log.warning("Astrometry.net API key not found in configuration file") |
110 |
| - log.warning("You need to manually edit the configuration file and add it") |
111 |
| - log.warning( |
112 |
| - "You may also register it for this session with AstrometryNet.key = 'XXXXXXXX'") |
113 | 125 | self._session_id = None
|
114 | 126 |
|
115 | 127 | def _login(self):
|
116 |
| - if not self.api_key: |
117 |
| - raise RuntimeError('You must set the API key before using this service.') |
118 | 128 | login_url = url_helpers.join(self.API_URL, 'login')
|
119 | 129 | payload = self._construct_payload({'apikey': self.api_key})
|
120 | 130 | result = self._request('POST', login_url,
|
|
0 commit comments