Home > Mobile >  Why am I getting question marks in my terminal as a response when I call an API (Node.js)
Why am I getting question marks in my terminal as a response when I call an API (Node.js)

Time:12-03

This is the response I am getting from the API

�x�\�¶��
'↓Xus!y
���X[m�e5����Ea�r�↔�p�♣cZ�$�y�:_��►V��M¶♥��b`▼7�G=�ը♠q▬`)M�v�a�Q4�c˄nME☺�*8Ù�A�h►�↔6{�E◄G6]`҄�#v-A�掰�9#�S(S�B[�
��5��a▼�Z崪�5�`��e�V�→�t0�L�QFe�7 "��♥‼5�.�T�l#��e
���b)↨�1§,↨§W��&�▲→�}SAG�;�Q�♣(/3�Y▲�:gC
�→↑��7�Eݞ^<�↨F‼����h�މ�e���1|▼�iD)y▼I��g�>@���→IB�♠;�����Sj→O☻��k$♠H8qrX��ʘc�r��Yd�w
Gh�Y�   �5]j¶�`�
ĵ8!�YV
►r\�J7U!#Y8� j �Gp�>H�@�↨���T�Uk�ڛ�↑♣�mE�§�tb��ֈ�¶♠�,�▬e�X�c�s���
]@ ∟�xT[�dAU���♠�ƒtۥ�(Zl�6d�§��Ps§g�ɜ�`U�U�ͅ↕ڣQx%�►��Q��� ��`,�{o(є�
Zp��Km��fsb,Ԭ�fq4�* ֔ޣ5PRn8:{fY�����;c�F�`%��1◄:��n���C��ͧ��~�V���ϑ�¶↑z��∟̭V]����{∟►�c�↑↕-D�y
�L���8΍,F'0��f.☻X!� kwa∟        Y��>▼"��z�Qc�uP$�♦r�h:��►Ҙʸ���@5        ∟��C/m�>��→ r��c▬W�
��jK36% ↨D��n��☺��vģ▼/��C�Qw��Nz ♣���Ďxs0vn��L�:��◄��zȽ�����_p�♣����K�l6�N�AMZݎ`>���˩���Q�
����y���X�a{����◄`l��qom�▬♥�c�▼��
p�zQ�↑�i▼�☺��о}¶ �� w���ݎ��5܂Lf?�♣��
C���‼UϘп¶z`��▲Rw�0|��ºDc▲Q�6Y]��_v!�7���@x�♦�ĉa���▼X��r
�`�§7�P#vy��8��!�}xT۹
↑↨Q�▬�h���~��☺►��M�u0V�EAZ�k� ↕)�"��ޙ]��R��m"�j)i�
ѕ�◄_��$YY�[S������x�}3_���↨��������4∟�$�o�hL��4k]�S‼��Z���☺F�H☻h�j���W�▬�ʜ♥�ּj���
 h� 6U�@��u@up→��#f
C A3[;�♥x]U�∟y��c��x}�O�պ��Җ§r����Q܀��p�↨��8�w=D�o��#x�CDs=��a
�1w↑s�i8����5�§→‼!{
��Y{,♦(䫾K��s4� �TPa{��↨�j��٩�☻��\���7Y�?������eFF      ���t���ªg�∟���G/�}y��`R;��      K5��2īpE
¶Ϩ�B�Ƃ�ؽE�▬�^0�ȉ�H,M=G^�d�'j��▬}N♦ϡ�2PS昚��b��j2k,�a�→6♣�t�↓��▬5↨�Xs�v��¶Ds�47��ƭ�a-�-6����↕&��&��▼�{�ss���XAG�a����*↕���aF��yM��p`-�♠�>� u�S��6dݠ���ž:��c����u^���qv�♥�C�=6�,dOE³
V�▲�:��ޫ�J∟(w
�K▲�}
‼5��!�#�����@8��Vv����ؕ$QD�0�ͭ�K @�☺R:��3�>�l"n�c�$Q����∟�-�,7�a���M�>↕���Kq§�YXf���uR��{8�
A!Q��,♠F;?��‼�&w�6
���
ն�����P�_�o�E�������?�r♣♦er.�m4�]�ǹgc�t�↨��↕��U#�ܢ
>��b#(9▼♥�ש��y�)►���☻l�n‼:fk�؆�"�

This is how I am calling the API

const getArtwork = async (req , res) => {
  await axios.get('https://api.rawg.io/api/games?token&key=3004a2').then(res => {
    console.log(res.data)
  })
};

The key in the code is wrong because I cannot post the real key here on stackoverflow. Is there a reason why I am getting these strange replies from the API and same also happened with the IGDB API (A different API for the same purpose). Am i doing something wrong?

CodePudding user response:

There are a few possible reasons why you might be seeing this in your terminal when you call an API.

First, it's possible that the API is returning data in a different encoding than your terminal is expecting. For example, if the API is returning data in UTF-8 format but your terminal is expecting data in ASCII format, you might see question marks instead of the actual characters in the response. To fix this issue, you can try specifying the encoding in the Content-Type header of your request, or you can try changing the encoding of your terminal to match the encoding of the API response.

Another possible reason is that the API is returning an error or invalid data in response to your request. This could be caused by a number of things, such as an incorrect API key, an invalid query parameter, or an issue with the API itself. To troubleshoot this issue, you can try checking the API documentation to make sure you're calling the API correctly, and you can also try using a tool like Postman to inspect the raw response from the API to see if there are any error messages or other clues as to what might be going wrong.

Finally, it's also possible that you are simply not handling the response from the API correctly in your code. For example, if you are trying to log the entire response object to the console, you might see question marks instead of the actual data if the response contains binary data (such as an image or audio file) that cannot be represented as text. To fix this issue, you can try logging only the specific data that you want to see, or you can try using a tool like Postman to inspect the response and make sure it contains the data you expect.

In summary, there are several possible reasons why you might be seeing question marks when calling an API, and the best way to troubleshoot the issue will depend on the specific details of your code and the API you are calling.

  • Related