<commit_before>import requests
from utils import json2xml, checkip
import json
import xmltodict
import logging

# global
headers = {'Content-Type': 'application/xml'}

class earthdata(object):

    def __init__(self):
        self.token = None
        self.base_url = 'https://cmr.earthdata.nasa.gov'

    def login(self,username, password):
        # see https://wiki.earthdata.nasa.gov/display/CMR/CMR+Client+Partner+User+Guide#CMRClientPartnerUserGuide-CreatingaToken
        if self.token is not None:
            logging.warning('Already logged into %s' % self.base_url)
            return True
        url = self.base_url +'/legacy-services/rest/tokens'
        self.ip = checkip()
        data ={'token': {'username': username, 
            'password': password, 
            'user_ip_address': self.ip, 'client_id': 'WRFXPY'}}
        try:
            r = requests.post(url, data=json2xml(data), headers=headers)
        except Exception as e:
            logging.error(e)
            return False
        if r.status_code == 201:
            try:
                self.token = xmltodict.parse(r.text)['token']['id']
                logging.info('Successfully logged into %s, token=%s' % (self.base_url, self.token))
                return True
            except:
                logging.error('%s did not return a token' % self.base_url)
        else:
            logging.error('%s return code %s' % (self.base_url, r.status_code))
        logging.error('Cannot log into %s' % self.base_url) 
        return False
    
    def logout(self):
        if self.token is None:
            logging.warning('Already logged out of %s' % self.base_url)
        else:
            url = self.base_url +'/legacy-services/rest/tokens/' + self.token
            try:
                r = requests.delete(url, headers=headers)
                if r.status_code == 204:
                    logging.info('Successfully logged out of %s' % self.base_url)
                    self.token = None
                    return
            except Exception as e:
                logging.error(e)
            logging.warning('Failed to log out of %s' % self.base_url)
     
    
<commit_msg>adding Client-ID to defaults headers<commit_after>import requests
from utils import json2xml, checkip
import json
import xmltodict
import logging

# global

class earthdata(object):

    def __init__(self):
        self.token = None
        self.base_url = 'https://cmr.earthdata.nasa.gov'
        self.headers = {'Content-Type': 'application/xml', 'Client-Id': 'WRFXPY'}

    def login(self,username, password):
        # see https://wiki.earthdata.nasa.gov/display/CMR/CMR+Client+Partner+User+Guide#CMRClientPartnerUserGuide-CreatingaToken
        if self.token is not None:
            logging.warning('Already logged into %s' % self.base_url)
            return True
        url = self.base_url +'/legacy-services/rest/tokens'
        self.ip = checkip()
        data ={'token': {'username': username, 
            'password': password, 
            'user_ip_address': self.ip, 'client_id': 'WRFXPY'}}
        try:
            r = requests.post(url, data=json2xml(data), headers=headers)
        except Exception as e:
            logging.error(e)
            return False
        if r.status_code == 201:
            try:
                self.token = xmltodict.parse(r.text)['token']['id']
                logging.info('Successfully logged into %s, token=%s' % (self.base_url, self.token))
                return True
            except:
                logging.error('%s did not return a token' % self.base_url)
        else:
            logging.error('%s return code %s' % (self.base_url, r.status_code))
        logging.error('Cannot log into %s' % self.base_url) 
        return False
    
    def logout(self):
        if self.token is None:
            logging.warning('Already logged out of %s' % self.base_url)
        else:
            url = self.base_url +'/legacy-services/rest/tokens/' + self.token
            try:
                r = requests.delete(url, headers=headers)
                if r.status_code == 204:
                    self.token = None
                    logging.info('Successfully logged out of %s' % self.base_url)
                    return
            except Exception as e:
                logging.error(e)
            logging.warning('Failed to log out of %s' % self.base_url)
     
    

{'fraction_non_alphanumeric': 0.11207092521027506, 'fraction_numerical': 0.0036371902705160265, 'mean_word_length': 1.925531914893617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1744686', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1253, 'n_words': 308}