CCXT.load_markets() function running fail in EC2 - python-3.x

I have a problem running ccxt.load_markets() function in EC2 server
but I check running is OK in local PC enviroment.
Please me help for solution
Code and Error msg is as below.
python version : 3.7.15
CCXT version : 2.2.95
import ccxt
import time
b= ccxt.binance()
print(b.milliseconds())
print(b.nonce())
print(b.load_markets())
1671012133696
1671012133696
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/ccxt/base/exchange.py", line 621, in fetch
response.raise_for_status()
File "/home/ec2-user/.local/lib/python3.7/site-packages/requests/models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 451 Client Error: for url: https://api.binance.com/api/v3/exchangeInfo
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 15, in
print(b.load_markets())
File "/usr/local/lib/python3.7/site-packages/ccxt/base/exchange.py", line 1448, in load_markets
markets = self.fetch_markets(params)
File "/usr/local/lib/python3.7/site-packages/ccxt/binance.py", line 1613, in fetch_markets
response = getattr(self, method)(query)
File "/usr/local/lib/python3.7/site-packages/ccxt/base/exchange.py", line 501, in inner
return entry(_self, **inner_kwargs)
File "/usr/local/lib/python3.7/site-packages/ccxt/binance.py", line 5854, in request
response = self.fetch2(path, api, method, params, headers, body, config, context)
File "/usr/local/lib/python3.7/site-packages/ccxt/base/exchange.py", line 2782, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/usr/local/lib/python3.7/site-packages/ccxt/base/exchange.py", line 639, in fetch
self.handle_http_status_code(http_status_code, http_status_text, url, method, http_response)
File "/usr/local/lib/python3.7/site-packages/ccxt/base/exchange.py", line 1741, in handle_http_status_code
raise ErrorClass(self.id + ' ' + method + ' ' + url + ' ' + codeAsString + ' ' + reason + ' ' + body)
ccxt.base.errors.ExchangeNotAvailable: binance GET https://api.binance.com/api/v3/exchangeInfo 451 {
"code": 0,
"msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error."
}

You are getting this error because the request to binance server is being sent from a restricted location. Binance blacklists some locations due to policies and regulation. Since you are running on aws EC2 instance, it is most likely that your virtual server is located in a restricted location. Using VPN is also risky since binance server are able to identify most of them. The solution would be to rent a virtual server that exists from binance legible locations.

Related

Cannot use custom key words with pvporcupine

I have already created an account in picovoice and recieved an access key, but when I try to put the path of my ppn file, it shows an error:
`
[ERROR] loading keyword file at 'C:\Users\Priyam\Desktop\hey keyazip' failed with 'IO_ERROR'
Traceback (most recent call last):
File "e:\Personal Project\import struct.py", line 13, in <module>
porcupine = pvporcupine.create(access_key='access key',
File "C:\Users\Priyam\AppData\Roaming\Python\Python310\site-packages\pvporcupine\__init__.py", line 77, in create
return Porcupine(
File "C:\Users\Priyam\AppData\Roaming\Python\Python310\site-packages\pvporcupine\porcupine.py", line 158, in __init__
raise self._PICOVOICE_STATUS_TO_EXCEPTION[status]()
pvporcupine.porcupine.PorcupineIOError
the code is:
`
porcupine=None
paud=None
audio_stream=None
try:
access_key="access key"
porcupine = pvporcupine.create(access_key='access key',
keyword_paths=['C:\\Users\Priyam\Desktop\hey keyazip'],keywords=['hey keya']) #pvporcupine.KEYWORDS for all keywords
paud=pyaudio.PyAudio()
audio_stream=paud.open(rate=porcupine.sample_rate,channels=1,format=pyaudio.paInt16,input=True,frames_per_buffer=porcupine.frame_length)
while True:
keyword=audio_stream.read(porcupine.frame_length)
keyword=struct.unpack_from("h"*porcupine.frame_length,keyword)
keyword_index=porcupine.process(keyword)
if keyword_index>=0:
print("hotword detected")
finally:
if porcupine is not None:
porcupine.delete()
if audio_stream is not None:
audio_stream.close()
if paud is not None:
paud.terminate()
`
I tried the code above and the code provided by picovoice itself, yet I am facing the same issues
It looks like Porcupine is having trouble finding your keyword file: [ERROR] loading keyword file at 'C:\Users\Priyam\Desktop\hey keyazip' failed with 'IO_ERROR'.
The Picovoice console provides the keyword inside a compressed .zip file. You will need to decompress the file and in your code update the path to lead to the .ppn file located inside. For example: C:\\Users\Priyam\Desktop\hey-keya_en_windows_v2_1_0\hey-keya_en_windows_v2_1_0.ppn

AWS secret manager time out sometimes

I am fetching a secret from secret manager on a lambda. The request fails sometimes. Which is totally strange, it is working fine and couple of hours later I check and I am getting time out.
def get_credentials(self):
"""Retrieve credentials from the Secrets Manager service."""
boto_config = BotoConfig(connect_timeout=3, retries={"max_attempts": 3})
secrets_client = self.boto_session.client(
service_name="secretsmanager",
region_name=self.boto_session.region_name,
config=boto_config,
)
secret_value = secrets_client.get_secret_value(SecretId=self._secret_name)
secret = secret_value["SecretString"]
I try to debug the lambda and later seems to be working again, without any change, those state changes happen in hours. Any hint why that could happen?
Traceback (most recent call last):
File "/opt/python/botocore/endpoint.py", line 249, in _do_get_response
http_response = self._send(request)
File "/opt/python/botocore/endpoint.py", line 321, in _send
return self.http_session.send(request)
File "/opt/python/botocore/httpsession.py", line 438, in send
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint URL: "https://secretsmanager.eu-central-1.amazonaws.com/"
You are using the legacy retry mode (is the default one in boto3), which has very limited functionality as it only works for a very limited number of errors.
You should try changing your retry strategy to something like Standard retry mode or Adaptative. In that case your code would look like:
from botocore.config import Config as BotoConfig
boto_config = BotoConfig(
connect_timeout=3,
retries={
"max_attempts": 3,
"mode":"standard"
}
)
secrets_client = self.boto_session.client(
service_name="secretsmanager",
region_name=self.boto_session.region_name,
config=boto_config,
)

Websocket error: "Handhshake status 403 forbidden"

i have a problem with my written code which i wrote with the help of this documentation: https://exchange.blockchain.com/api/#introduction.
The code should send messages, receive messages and then i want to work with the received messages. And that 3 times per day (in the morning, noon and evening).
However the code seems to be working sometimes, actually up to 6 days (record, yay!) and then it stops working and i get an error output:
Traceback (most recent call last):
File "<ipython-input-1-052db9d33d34>", line 1, in <module>
runfile('Pathtofile/File.py', wdir='workingdirectory')
File "C:\Users\iamdabest\Downloads\latexNpython\WinPython64-3.6.8.0\python-
3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line
786, in runfile
execfile(filename, namespace)
File "C:\Users\orami?\Downloads\latexNpython\WinPython64-3.6.8.0\python-
3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line
110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "Pathtofile/File.py", line 235, in <module>
main()
File "Pathtofile/File.py", line 229, in main
trigger(updater.bot)
File "Pathtofile/File.py", line 171, in trigger
y = price_func()[0]
File "Pathtofile/File.py", line 46, in price_func
ws = create_connection(url, **options)
File "C:\Users\name\Downloads\latexNpython\WinPython64-3.6.8.0\python-
3.6.8.amd64\lib\site-packages\websocket\_core.py", line 606, in
create_connection
websock.connect(url, **options)
File "C:\Users\name\Downloads\latexNpython\WinPython64-3.6.8.0\python-
3.6.8.amd64\lib\site-packages\websocket\_core.py", line 253, in connect
self.handshake_response = handshake(self.sock, *addrs, **options)
File "C:\Users\name\Downloads\latexNpython\WinPython64-3.6.8.0\python-
3.6.8.amd64\lib\site-packages\websocket\_handshake.py", line 57, in handshake
status, resp = _get_resp_headers(sock)
File "C:\Users\name\Downloads\latexNpython\WinPython64-3.6.8.0\python-
3.6.8.amd64\lib\site-packages\websocket\_handshake.py", line 143, in
_get_resp_headers
raise WebSocketBadStatusException("Handshake status %d %s", status,
status_message, resp_headers)
WebSocketBadStatusException: Handshake status 403 Forbidden
Now please keep in mind that i never got teached this stuff by a trained professional. All the knowledge i gained is from playing around (plotting and analyzing data) with python and the help of the internet.
I don't really understand why it is working few days and then suddenly stops working.
My questions:
In fact i have no problem when the codes doesn't gives an output as long as it keeps running. So how can i tell the code to 'ignore' the error and keep moving or maybe to automatic restart the code if the error occurs? I tried simple stuff like if statement or try and expect but i wasn't successful.
The error comes because the authentication between Server and Client failed? or what does it mean?
Is there another workaround? I already read somewhere to use another websocket (websockets) but wasn't able to get it working.
Here is a (M)WE of my code:
from websocket import create_connection
import json
options = {}
options['origin'] = 'https://exchange.blockchain.com'
url = "wss://ws.prod.blockchain.info/mercury-gateway/v1/ws"
def price_func():
ws = create_connection(url, **options)
msg = '{"token": "mysecretAPItoken", "action": "subscribe", "channel": "auth"}' # here i subscribe
ws.send(msg)
msg = '{"action": "subscribe", "channel": "balances"}' # here i am asking for the json files
ws.send(msg)
result1 = json.loads(ws.recv()) # first answer is the confirmation of connecting
result2 = json.loads(ws.recv()) # save the received answers to work with them later
msg = '{"token": "mysecretAPItoken", "action": "unsubscribe", "channel": "balances"}' # unsubscribing, not sure if i need to do that but it seems to me like 'clean' working; if smth goes wrong it unsubscribes.
ws.send(msg)
msg = '{"token": "mysecretAPItoken", "action": "unsubscribe", "channel": "auth"}' # unsubscribing; same as 3 lines above
ws.send(msg)
ws.close()
return result2['balances'][0]['rate'], result2['balances'][1]['rate'] # gives me the prices
x = price_func()[0]
print('Price of Shitcoin is around' + str(round(x,2)))
Thx for any help.

Snowflake connector.connect breaks with an error message that tells me nothing

I installed the snowflake connector via the command: pip3 install snowflake-connector-python[pandas]==2.3.3 asn1crypto==1.3.0 --user
I attempted to connect via:
from snowflake import connector
con = connector.connect(
host='.snowflakecomputing.com',
user='THE USER I USE FOR LOGGING IN TO MY TRIAL ACCOUNT',
password='THE PASSWORD I USE FOR LOGGING IN TO MY TRIAL ACCOUNT',
account='zka81761.us-east-1',
warehouse='COMPUTE_WH',
database='DEMO_DB',
schema='PUBLIC',
protocol='https',
port=443)
When executing the above code it just hangs for several minutes then I get an error:
snowflake.connector.errors.OperationalError: 250003: Failed to execute request: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
The longer version is:
File "tests/integration_tests/data_sources/test_snowflake_ds.py", line 6, in test_snowflake_ds
ds = SnowflakeDS(query='SELECT * FROM HEALTHCARE_COSTS', host='.snowflakecomputing.com', user='GEORGE3D6', password='a passwordd', account='zka81761.us-east-1', warehouse='COMPUTE_WH', database='DEMO_DB', schema='PUBLIC', protocol='https', port=443)
File "/home/george/mindsdb_native/mindsdb_native/libs/data_types/data_source.py", line 13, in __init__
df, col_map = self._setup(*args, **kwargs)
File "/home/george/mindsdb_native/mindsdb_native/libs/data_sources/snowflake_ds.py", line 21, in _setup
port=port)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/__init__.py", line 52, in Connect
return SnowflakeConnection(**kwargs)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/connection.py", line 219, in __init__
self.connect(**kwargs)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/connection.py", line 414, in connect
self.__open_connection()
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/connection.py", line 613, in __open_connection
self._authenticate(auth_instance)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/connection.py", line 839, in _authenticate
self.__authenticate(self.__preprocess_auth_instance(auth_instance))
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/connection.py", line 869, in __authenticate
session_parameters=self._session_parameters,
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/auth.py", line 209, in authenticate
socket_timeout=self._rest._connection.login_timeout)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/network.py", line 509, in _post_request
_include_retry_params=_include_retry_params)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/network.py", line 586, in fetch
**kwargs)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/network.py", line 676, in _request_exec_wrapper
conn, full_url, cause)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/network.py", line 706, in handle_invalid_certificate_error
'errno': ER_FAILED_TO_REQUEST,
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/errors.py", line 128, in errorhandler_wrapper
connection.errorhandler(connection, cursor, error_class, error_value)
File "/home/george/.local/lib/python3.7/site-packages/snowflake/connector/errors.py", line 90, in default_errorhandler
done_format_msg=error_value.get('done_format_msg'))
snowflake.connector.errors.OperationalError: 250003: Failed to execute request: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
This error message tells me nothing, any help would be appreicated
According to the documentation on the python API the host field is no longer used so try removing that. Also, even if it was used, you haven't enclosed it properly in quotes:
You have: host='.snowflakecomputing.com,
Should be: host='.snowflakecomputing.com',
First, I'd see if removing the host completely fixes your issue since it shouldn't be used anyway.
Googling the error, and the error message itself, suggests that the issue is due to the URL being too long so I'd say the error is down to the fact that you haven't enclosed it properly.
I used to connect snowflake from python like below:
import snowflake.connector as sf
sfconnection = sf.connect(
user='THE USER I USE FOR LOGGING IN TO MY TRIAL ACCOUNT',
password='THE PASSWORD I USE FOR LOGGING IN TO MY TRIAL ACCOUNT',
account='zka81761.us-east-1',
warehouse='COMPUTE_WH',
database='DEMO_DB',
schema='PUBLIC')
Apparently the docs are wrong and the host should now be the full URL (so, in my case zka81761.us-east-1.snowflakecomputing.com). That is to say, it should include the account.

Jira Python API to insert comment with WIKI formatting

While using jira python module to add comments, is there a possibility to insert comments using WIKI markup?
I noticed some example showed REST API calls with representation:wiki can do this.
But I noticed current python Jira only supports plain text as comments. Is this a limitation or I am missing something?
I checked jira source code and noticed data is represented as dictionary and also being dumped using json.dumps, I tried pushing body as dict "{'storage': {'value': '== Activity: == error-rate-percentage-is-at-acceptable-limits .. Started', 'representation': 'wiki'}}"
But got below error back from Jira API call I guess
[2019-12-02 01:07:22 DEBUG] [__init__:386] Before-control 'jira-integration' failed
Traceback (most recent call last):
File "<<HIDDEN BY ME>>>/lib/python3.7/site-packages/chaoslib/control/__init__.py", line 377, in apply_controls
settings=settings)
File "<<HIDDEN BY ME>>>/python3.7/site-packages/chaoslib/control/python.py", line 147, in apply_python_control
func(context=context, **arguments)
File "<<HIDDEN BY ME>>>/python3.7/site-packages/<<HIDDEN BY ME>>/controls/jira/tickets.py", line 220, in before_activity_control
add_comment(os.environ["SUB_TASK_TICKET"], content_as_wiki(formatting.format_as_heading2("Activity: ") + str(context["name"]) + " .. Started"))
File "<<HIDDEN BY ME>>>/python3.7/site-packages/<<HIDDEN BY ME>>/controls/jira/tickets.py", line 58, in add_comment
test = JIRA_CLIENT.add_comment(issue, comment)
File "<<HIDDEN BY ME>>/python3.7/site-packages/jira/client.py", line 126, in wrapper
result = func(*arg_list, **kwargs)
File "<<HIDDEN BY ME>>/python3.7/site-packages/jira/client.py", line 1367, in add_comment
url, data=json.dumps(data)
File "<<HIDDEN BY ME>>/python3.7/site-packages/jira/resilientsession.py", line 154, in post
return self.__verb('POST', url, **kwargs)
File "<<HIDDEN BY ME>>/python3.7/site-packages/jira/resilientsession.py", line 147, in __verb
raise_on_error(response, verb=verb, **kwargs)
File "<<HIDDEN BY ME>>/python3.7/site-packages/jira/resilientsession.py", line 57, in raise_on_error
r.status_code, error, r.url, request=request, response=r, **kwargs)
jira.exceptions.JIRAError: JiraError HTTP 400 url: https://<<HIDDEN BY ME>>>
text: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: com.enhancera.auditor.common.filter.RestReadingServletRequest$1#4e08280a; line: 1, column: 2] (through reference chain: com.atlassian.jira.issue.fields.rest.json.beans.CommentJsonBean["body"])
I was able to create a comment using markup by passing a string formatted according to the documentation here. For a test I created an issue and added a comment to add a two column 1 row (+ header row) table with:
comment = jira.add_comment(issue, "||header1||header2||\n|one|two|")
Which produced:
Make sure to wrap your comment string in double quotes.

Resources