Changeset 4372
- Timestamp:
- Mar 18, 2020 5:25:22 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r4365 r4372 2227 2227 return Layer 2228 2228 2229 def postURL(URL,postdict): 2230 '''Posts a set of values as from a web form. If access fails to an http 2231 site the access is retried with https 2232 :param str URL: the URL to post; typically something 2233 like 'http://www.../dir/page?' 2234 :param dict postdict: contains keywords and values, such 2235 as {'centrosymmetry': '0', 'crystalsystem': '0', ...} 2236 :returns: a string with the response from the web server or None 2237 if access fails. 2238 ''' 2239 try: 2240 import requests # delay this until now, since rarely needed 2241 except: 2242 # this import seems to fail with the Anaconda pythonw on 2243 # macs; it should not! 2244 print('Warning: failed to import requests. Python config error') 2245 return None 2246 2247 repeat = True 2248 while repeat: 2249 r = None 2250 repeat = False 2251 try: 2252 r = requests.get(URL,params=postdict) 2253 if r.status_code == 200: 2254 print('request OK') 2255 page = r.text 2256 return page # success 2257 else: 2258 print('request to {} failed. Reason={}'.format(URL,r.reason)) 2259 except Exception as msg: #ConnectionError? 2260 print('connection error - not on internet?') 2261 if GSASIIpath.GetConfigValue('debug'): print(msg) 2262 finally: 2263 if r: r.close() 2264 if URL.startswith('http:'): 2265 repeat = True 2266 URL = URL.replace('http:','https:') 2267 else: 2268 return None 2269 2229 2270 if __name__ == '__main__': 2230 2271 import GSASIIdataGUI -
trunk/SUBGROUPS.py
r4365 r4372 16 16 ########### SVN repository information ################### 17 17 from __future__ import division, print_function 18 import requests19 18 import numpy as np 20 19 import numpy.linalg as nl 21 20 import GSASIIspc as G2spc 21 import GSASIIIO as G2IO 22 22 import GSASIIpath 23 23 GSASIIpath.SetBinaryPath() 24 submagSite = 'http s://www.cryst.ehu.es/cgi-bin/cryst/programs/subgrmag1_general_GSAS.pl?'24 submagSite = 'http://www.cryst.ehu.es/cgi-bin/cryst/programs/subgrmag1_general_GSAS.pl?' 25 25 26 26 def GetNonStdSubgroups(SGData, kvec,star=False,landau=False,maximal=False): … … 83 83 for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]): 84 84 postdict['knm%d%s'%(j,i)] = k 85 try: 86 r = requests.get(submagSite,params=postdict) 87 except: #ConnectionError? 88 page = '' 89 print('connection error - not on internet') 85 page = G2IO.postURL(submagSite,postdict) 86 if not page: 87 print('connection error - not on internet?') 90 88 return None,None 91 if r.status_code == 200: 92 print('request OK') 93 page = r.text 94 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 95 else: 96 page = '' 97 print('request failed. Reason=',r.reason) 98 return None,None 99 r.close() 100 89 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 101 90 result = page.replace('&','\n') 102 91 result = result.split('\n') … … 211 200 for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]): 212 201 postdict['km%d%s'%(j,i)] = k 213 try: 214 r = requests.get(submagSite,params=postdict) 215 except: #ConnectionError? 216 page = '' 217 print('connection error - not on internet') 202 page = G2IO.postURL(submagSite,postdict) 203 if not page: 204 print('connection error - not on internet?') 218 205 return None,None 219 if r.status_code == 200: 220 print('request OK') 221 page = r.text 222 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 223 else: 224 page = '' 225 print('request failed. Reason=',r.reason) 226 return None,None 227 r.close() 228 206 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 229 207 result = page.replace('&','\n') 230 208 result = result.split('\n') … … 283 261 datastr = "sgr={:}&cell={:}&tol={:}&submit=Show".format( 284 262 str(int(spgNum)),cellstr,str(int(tol))) 285 try: 286 r = requests.get(psSite,params=datastr) 287 except: #ConnectionError? 288 page = '' 289 print('connection error - not on internet') 263 page = G2IO.postURL(psSite,datastr) 264 if not page: 265 print('connection error - not on internet?') 290 266 return None 291 if r.status_code == 200: 292 print('request OK') 293 page = r.text 294 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 295 else: 296 page = '' 297 print('request failed. Reason=',r.reason) 298 return None 299 r.close() 267 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 300 268 return page 301 269 -
trunk/kSUBGROUPSMAG.py
r4365 r4372 16 16 ########### SVN repository information ################### 17 17 from __future__ import division, print_function 18 import requests19 18 try: 20 19 import HTMLParser as HTML … … 22 21 import html.parser as HTML # Python 3 23 22 import GSASIIspc as G2spc 23 import GSASIIIO as G2IO 24 24 import GSASIIpath 25 25 GSASIIpath.SetBinaryPath() … … 140 140 for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]): 141 141 postdict['km%d%s'%(j,i)] = k 142 try: 143 r = requests.get(submagSite,params=postdict) 144 except: #ConnectionError? 145 page = '' 146 print('connection error - not on internet') 142 page = G2IO.postURL(submagSite,postdict) 143 if not page: 144 print('connection error - not on internet?') 147 145 return None,None 148 if r.status_code == 200: 149 print('request OK') 150 page = r.text 151 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 152 else: 153 page = '' 154 print('request failed. Reason=',r.reason) 155 return None,None 156 r.close() 157 146 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 158 147 p = TableParser() 159 148 p.feed(page) … … 213 202 for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]): 214 203 postdict['knm%d%s'%(j,i)] = k 215 try: 216 r = requests.get(submagSite,params=postdict) 217 except: #ConnectionError? 218 page = '' 219 print('connection error - not on internet') 220 return None 221 if r.status_code == 200: 222 print('request OK') 223 page = r.text 224 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 225 else: 226 page = '' 227 print('request failed. Reason=',r.reason) 228 return None 229 r.close() 230 204 if not page: 205 print('connection error - not on internet?') 206 return None,None 207 page = page.replace('<font style= "text-decoration: overline;">','<font>-') 231 208 p = TableParser() 232 209 p.feed(page)
Note: See TracChangeset
for help on using the changeset viewer.