mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-04 01:21:03 +03:00
Set connection timeout on Companion and EDDN network interactions.
This commit is contained in:
parent
1110d978f4
commit
3cc6a7f54f
@ -19,6 +19,7 @@ if __debug__:
|
|||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
holdoff = 120 # be nice
|
holdoff = 120 # be nice
|
||||||
|
timeout = 10 # requests timeout
|
||||||
|
|
||||||
|
|
||||||
# Map values reported by the Companion interface to names displayed in-game and recognized by trade tools
|
# Map values reported by the Companion interface to names displayed in-game and recognized by trade tools
|
||||||
@ -112,7 +113,7 @@ class Session:
|
|||||||
raise CredentialsError()
|
raise CredentialsError()
|
||||||
else:
|
else:
|
||||||
self.credentials = { 'email' : username, 'password' : password }
|
self.credentials = { 'email' : username, 'password' : password }
|
||||||
r = self.session.post('https://companion.orerve.net/user/login', data = self.credentials)
|
r = self.session.post('https://companion.orerve.net/user/login', data = self.credentials, timeout=timeout)
|
||||||
if r.status_code != requests.codes.ok:
|
if r.status_code != requests.codes.ok:
|
||||||
self.dump(r)
|
self.dump(r)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
@ -131,8 +132,7 @@ class Session:
|
|||||||
return r.status_code
|
return r.status_code
|
||||||
|
|
||||||
def verify(self, code):
|
def verify(self, code):
|
||||||
r = self.session.post('https://companion.orerve.net/user/confirm',
|
r = self.session.post('https://companion.orerve.net/user/confirm', data = {'code' : code}, timeout=timeout)
|
||||||
data = { 'code' : code })
|
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
# verification doesn't actually return a yes/no, so log in again to determine state
|
# verification doesn't actually return a yes/no, so log in again to determine state
|
||||||
try:
|
try:
|
||||||
@ -147,7 +147,7 @@ class Session:
|
|||||||
self.login()
|
self.login()
|
||||||
elif self.state == Session.STATE_AUTH:
|
elif self.state == Session.STATE_AUTH:
|
||||||
raise VerificationRequired()
|
raise VerificationRequired()
|
||||||
r = self.session.get('https://companion.orerve.net/profile')
|
r = self.session.get('https://companion.orerve.net/profile', timeout=timeout)
|
||||||
|
|
||||||
if r.status_code != requests.codes.ok:
|
if r.status_code != requests.codes.ok:
|
||||||
self.dump(r)
|
self.dump(r)
|
||||||
|
4
eddn.py
4
eddn.py
@ -13,6 +13,8 @@ from config import applongname, appversion, config
|
|||||||
upload = 'http://eddn-gateway.elite-markets.net:8080/upload/'
|
upload = 'http://eddn-gateway.elite-markets.net:8080/upload/'
|
||||||
schema = 'http://schemas.elite-markets.net/eddn/commodity/2'
|
schema = 'http://schemas.elite-markets.net/eddn/commodity/2'
|
||||||
|
|
||||||
|
timeout= 10 # requests timeout
|
||||||
|
|
||||||
bracketmap = { 1: 'Low',
|
bracketmap = { 1: 'Low',
|
||||||
2: 'Med',
|
2: 'Med',
|
||||||
3: 'High', }
|
3: 'High', }
|
||||||
@ -20,7 +22,7 @@ bracketmap = { 1: 'Low',
|
|||||||
def export(data):
|
def export(data):
|
||||||
|
|
||||||
def send(msg):
|
def send(msg):
|
||||||
r = requests.post(upload, data=json.dumps(msg))
|
r = requests.post(upload, data=json.dumps(msg), timeout=timeout)
|
||||||
if __debug__ and r.status_code != requests.codes.ok:
|
if __debug__ and r.status_code != requests.codes.ok:
|
||||||
print 'Status\t%s' % r.status_code
|
print 'Status\t%s' % r.status_code
|
||||||
print 'URL\t%s' % r.url
|
print 'URL\t%s' % r.url
|
||||||
|
Loading…
x
Reference in New Issue
Block a user