Ignore:
Timestamp:
Mar 18, 2020 5:25:22 PM (4 years ago)
Author:
toby
Message:

streamline Post access to web pages; try http before https

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kSUBGROUPSMAG.py

    r4365 r4372  
    1616########### SVN repository information ###################
    1717from __future__ import division, print_function
    18 import requests
    1918try:
    2019    import HTMLParser as HTML
     
    2221    import html.parser as HTML # Python 3
    2322import GSASIIspc as G2spc
     23import GSASIIIO as G2IO
    2424import GSASIIpath
    2525GSASIIpath.SetBinaryPath()
     
    140140        for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]):
    141141            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?')
    147145        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>-')
    158147    p = TableParser()
    159148    p.feed(page)
     
    213202        for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]):
    214203            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>-')
    231208    p = TableParser()
    232209    p.feed(page)
Note: See TracChangeset for help on using the changeset viewer.