Forums

GET method is not working when used with Binance.

Until a few days ago my bot was working fine on the pythonanywhere platform. Now I have discovered that the GET method is not loading and the variable that brings that data from Binance.com is empty. Can you please tell me what should I do?

Could you give some more details -- perhaps sharing your code (stripped of any private information like passwords, of course)?

This is the error that is being generated. Content is not being fetched from Binance 2022-12-06 19:08:24,069: Exception on /appxxx... [POST] Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/eagle69/eagleWEB/flask_app.py", line 21, in eagle1 eagle1.Entrar(parametro) File "/home/eagle69/./FuturosBot.py", line 52, in Entrar pos = self.PosicionActual(self.ticker) File "/home/eagle69/./FuturosBot.py", line 36, in PosicionActual return c.ObtenerPosicion(ticker) File "/home/eagle69/./FuturosConsultas.py", line 41, in ObtenerPosicion for item in p: TypeError: 'NoneType' object is not iterable

Locally it works excellent for me. But since pythonanywhere I am having problems.

The section that fails me is the following:

import requests from Binance import Binance ... ... ... def ObtenerCuentaGeneral(self) -> dict: endPoint = self.Fut_url + "/fapi/v2/account" parametro = "timestamp=" + str(self.ObtenerFechaServer()) parametro = self.Firmar(parametro) h = self.Encabezados(self.apiKey) r = requests.get(endPoint,params=parametro, headers=h) return r.json()

def ObtenerPosiciones(self) -> dict:
    ac=self.ObtenerCuentaGeneral()
    if "positions" in ac.keys():
        return ac["positions"] 
    return None

def ObtenerPosicion(self, simbolo:str) -> dict:
    p=self.ObtenerPosiciones()
    ticker=simbolo.upper()
    for item in p:
        if item["symbol"] == ticker:
            self.Log(item["symbol"] + "->" + " " + item["positionAmt"]) 
            return float(item["positionAmt"])
    return 0.0

The pricipal section is:

import socket import requests import json import hmac import hashlib from datetime import datetime class Binance: apiKey = "" secretKey = ""
Spot_url = "" Fut_url = ""

def __init__(self):
    ....
    ...

ObtenerPosiciones is returning None, it should be returning empty dict to be able not to crash when you try to iterate over it.