Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The weird HTTP POST data transfer problem using curl.

253 views
Skip to first unread message

hongy...@gmail.com

unread,
Jun 10, 2021, 10:22:35 AM6/10/21
to
On Ubuntu 20.04, I try to test the MathpixOCR JSON API with curl as described on <https://docs.mathpix.com/?shell#introduction>:

curl -X POST https://api.mathpix.com/v3/text \
-H 'app_id: YOUR_APP_ID' \
-H 'app_key: YOUR_APP_KEY' \
-H 'Content-Type: application/json' \
--data '{ "src": "data:image/jpeg;base64,'$(base64 -i limit.jpg)'" }'

I tested with the following commands:

1. Pass the value of ``--data'' as below works:

$ curl -x socks5://127.0.0.1:18888 -X POST https://api.mathpix.com/v3/text \
-H 'app_id: my-app-id' \
-H 'app_key: my-app-key' \
-H 'Content-Type: application/json' \
--data "$(echo '{ "src": "data:image/jpeg;base64,'$(base64 -i schrodinger.png)'" }' )"
{"request_id":"4bf91ee2f4cf29fc571e2d66accfce17","is_printed":true,"is_handwritten":false,"auto_rotate_confidence":0.00018956642596990037,"auto_rotate_degrees":0,"confidence":1,"confidence_rate":1,"latex_styled":"i \\hbar \\frac{\\partial}{\\partial t} \\Psi(x, t)=\\left[-\\frac{\\hbar^{2}}{2 m} \\frac{\\partial^{2}}{\\partial x^{2}}+V(x, t)\\right] \\Psi(x, t)","text":"\\( i \\hbar \\frac{\\partial}{\\partial t} \\Psi(x, t)=\\left[-\\frac{\\hbar^{2}}{2 m} \\frac{\\partial^{2}}{\\partial x^{2}}+V(x, t)\\right] \\Psi(x, t) \\)"}

2. Pass the value of ``--data'' as below failed:

$ curl -x socks5://127.0.0.1:18888 -X POST https://api.mathpix.com/v3/text \
-H 'app_id: my-app-id' \
-H 'app_key: my-app-key' \
-H 'Content-Type: application/json' \
--data '{ "src": "data:image/jpeg;base64,'$(base64 -i schrodinger.png)'" }'
{"error":"SyntaxError: Unexpected end of JSON input","error_info":{"id":"json_syntax","message":"SyntaxError: Unexpected end of JSON input"}}curl: (6) Could not resolve host: AElEQVR4nO2dS2wb1
curl: (6) Could not resolve host: kGRL8qY1SdkyChQJKdlSFwHMh+1FNxFJSUA2rUjJ3rRAxCHlRdMA4txvcf46vd
curl: (6) Could not resolve host: Hr6Ohvfec+952iilhMPhcDgc62ixWgAOh8PhvO1wVcThcDgci+GqiMPhcDgWw1URh8PhcCyGqyIO
curl: (6) Could not resolve host: h8PhWAxXRRwOh8OxGK6KOBwOh2MxXBVxOBwOx2K4KuJwOByOxfzCagE4HAuAIiM2m81qQbRg9ZMm
curl: (6) Could not resolve host: lI3DOT74qYjzdlEoFEZHR997772Wlpa+vr7l5WWrJfof8Xi8u7u7paWlvb19dHQ0n89bLRGH0yBs
curl: (6) Could not resolve host: vAYdp3Y2Nzd
curl: (6) Could not resolve host: ZaW1tfXJkydjY2Otra2pVKq1tdVq0Tj
curl: (6) Could not resolve host: fmh99NFHqqpaLd3
curl: (6) Could not resolve host: 9eP8
curl: (6) Could not resolve host: TVVVeJBOpy9cuGD4mo2NjUKhsLS0ND4+TggRRdHpdL58+TKdTvf39x+3hLFY7PHjx69evRIEwel0
curl: (6) Could not resolve host: gp0Qn3358iUhJJVKgSQ9PT0gMKWUD
curl: (6) Could not resolve host: evXq
curl: (6) Could not resolve host: VvnjXuvBGJhOp0dGRux2e6FQuHPnzldffRWJREDx2Gy25eXl58+fd3d3o2yshJxmYHh4eHh4GP+r
curl: (6) Could not resolve host: qupf
curl: (6) Could not resolve host: GAQDnSAIx21IdLlcLpeLNQPu7e3JsiyK4vr6uuFbvF4vIcTn8x2rYJxaKBaLbW1t3EBXF5orgi4U
curl: (6) Could not resolve host: Cu3u7r5584a9eOHChdnZ2c3NzRs3blglGKeZoZTGYjGfzwf
curl: (6) Could not resolve host: hULHevKIxWKrq6v7+
curl: (6) Could not resolve host: Uh0cHLBP7e3twXV+MGpCrD0VJZNJ8xFe6mARj8cJIaFQ6LglnJiYAEmi0Sh7vVgsguNBfzByOp2y
curl: (6) Could not resolve host: LGMIA6c54aeiOtJEviKbzSbL8suXL6enp1nvNyEE41nT6fSlS5eskI7TpHR3d4OB7ubNm1tbW4SQ
curl: (6) Could not resolve host: Z8+esaccwxCGdDo9NjYWiURY0
curl: (6) Could not resolve host: DqdZsFoXajHcXxwcHIC03HTehFjuK6KUFotFQRAIIbIsH+n4URRFkqRUKgX
curl: (6) Could not resolve host: eGgGcDqd+MrZ2VmPx4Mv4MHczQw
curl: (6) Could not resolve host: tNlssNzbDmFfmc
curl: (6) Could not resolve host: o0eP4L+7u7sbGxvHKhiH0yQ0lypKJpOffvrp7u7utWvXPvvsM0LIw4cP0+k0BHZzOKV4
curl: (6) Could not resolve host: YWRkZHV1FaIVPB7PrVu3UNMUCoX+
curl: (6) Could not resolve host: tbU9evRoaWkpGo2CKoLz3PLy8vj4eG9vL8Sa22y2QqGA3lMO55Rj8amMIRgMEkIkSWK9uAcHB3a7
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: 44HNFiEEshdAWg2zs7PHJxunRriBro40iypaX1+HuaePJsIgXUJIJpOxRDyOCZarInQUgeLB9B1I
curl: (6) Could not resolve host: zWGHjaqqRR3Hl1SUy+UcDgchZHp6WvNUNBrFUQ1aSi8YX+CaHK6K6khTGOgopRDI5HK59PFOEIBE
curl: (6) Could not resolve host: COno6OAFFzh60FEkSVI8Hod4S0opZhRhiesGFy+4cePG7u6uIAg3b97UPNXZ2YmP+
curl: (6) Could not resolve host: 5MfhNJKmGP2hUOj169eEEJfLpX92d3cXHvT09PAiKBw96Cjy+
curl: (6) Could not resolve host: duvVDMYjOJ1OXnubw7FeFVFKl5aW4PHly5f1L8AoI15tgaOHUvrixQt4zIa3ZLNZDFezRDAo5UAI
curl: (6) Could not resolve host: wZJ3LHhi83g8fIPF4TSFKoKaxLIs60tY4kLjdDq5dY6jhx0
curl: (6) Could not resolve host: EQRhaGiooZJxOE2J9aoIMbS
curl: (6) Could not resolve host: VwkhXq
curl: (6) Could not resolve host: FPBuDIIg6LdQi4uL+
curl: (6) Could not resolve host: 4Ha7KaULCwuSJEGgWmOA+nLwWDOwc7nc119
curl: (6) Could not resolve host: +9vfWCtKMpn87W9
curl: (6) Could not resolve host: 3NycmZlpcLT0rVu3BEHY2trKZrN4UVGUjz
curl: (6) Could not resolve host: FVEoFLq7u3d2dqwSoJ63q5akJFVVDw4OotFoPB6PxWLZbLbqj5qZmSGEyLLs8
curl: (6) Could not resolve host: 1tgVAqpPQhpjdbmNiqJ0dnbC5tpCIAU4GAxaK4YhFqa4lqqTCwVPcZBbdd8ikYggCKIo+v1+v98
curl: (6) Could not resolve host: MjIiiqLdbi
curl: (6) Could not resolve host: v7q+hMNhQRBqH9LlqqLt7e1IJKK5CAqjXhM+Fou53W6n0+l0Or1ebywWqz0Nnq3UoKecMkLQOea4
curl: (6) Could not resolve host: u3yWw
curl: (6) Could not resolve host: drt+Wum74gYCAf1rNPchl8uJojgxMdHYP8IAqCMlSRLbddeQqlUR25utuqUJtsgul6ui7z0mJiYm
curl: (6) Could not resolve host: RFGssRROWapoe3sbbpBGA7tcLtZXXJeqPGwV
curl: (6) Could not resolve host: FovVS55yyOfzs7Oz+iOmqqo9PT2SJDVb
curl: (6) Could not resolve host: QFzS4OBgOBzWd+XweDyCIDR4bCuKMjs7q29RqCgKtAUwf3stp6JkMgl3D9wTsDSFw2G4eGTXRJ
curl: (6) Could not resolve host: JwhCgwuhwdKkXzZVVZUkqaenp5YPL0sVwX5co6vD4bDf72ePHfBfsLA1ePk+kmKxCEI6nc7yz7+i
curl: (6) Could not resolve host: KDZ+3wG31HB7CIXLmq1pE1dFJ50aD464CJgbiyRJwlZMGmBgN97WBErU0JwzNTV15OmkLjXo0MjM
curl: (6) Could not resolve host: tq0yB84GjV8HwAxm+L2gIwztE2VSroFuenqa
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: MbGGwXJvvo5Vqorih7AXS6mivb09eLHeQOJ2uwkhDbY8Y9FhTY15IJfLCYJQiy+j+rAFsDlg8eNv
curl: (6) Could not resolve host: v
curl: (6) Could not resolve host: B0Z1qV0dLPqNjwxCDVpqjkPnEZMVvyJVVCwWcfvOng4NVVEsFsOlSXNoy+VyhJAarWFVgGl5e3t7
curl: (6) Could not resolve host: hi8AXVC1M7v68FZI3MNSWl1dXWcYLKyM8Pz5cyg7trm5uby8bPLKe
curl: (6) Could not resolve host: PT0NjgCGkHFBELDHqAbInsGqaxxOjdCa80KwyjgUNdZ
curl: (6) Could not resolve host: oa6RlpaWnZ0diFZYWlpKJpMmL56bm4OlKRqNjo+Ps0+trKwQQi5evFgXqcoHlqaOjo5SyXAdHR3k
curl: (6) Could not resolve host: sKJVFRyxzoIyTKVSpZ6FNVGSpPb29mKxGIvF4vG4oijVSVMvRkZG4AHWZtZDmTKa+jpg8JT59FBV
curl: (6) Could not resolve host: VfP3qqqKB
curl: (6) Could not resolve host: xiKKosDMws
curl: (6) Could not resolve host: EGmWpkQiUd3SdHBwALnkuDTpX4m75Co3NyYnplQqJUkStAtyuVx6mxtG1rlcLo
curl: (6) Could not resolve host: tBigGDiC0UDHxlNqztf4lImjaH193eFw2O12uD+BQCCfz8uHOByOI8PzkCLT+U2D
curl: (6) Could not resolve host: A92JpnYDXbFYhB2xfipB80BDxyf77fo3sgSDQVEUOzo6JEmCjB
curl: (6) Could not resolve host: yVZF2AIuTWhjxzvg9Xo1V
curl: (6) Could not resolve host: FsjqxlJJVaQoisPhCAQCxWIRDoP6n4pNFxAEwefzRaNRcKkRSzNg0PyKcWj6XxdiowkhHR0dmt8b
curl: (6) Could not resolve host: YwdK
curl: (6) Could not resolve host: 4bgqOtHAZKlFFVFK0V6kCT2YmJgwd2XDdpZt+q4hGAzKspxMJlVV3dvbg+VVFMVwOJzP52EKlx9b
curl: (6) Could not resolve host: lM
curl: (6) Could not resolve host: C4Oo8Xbpl6ZydvAmlFRF09PTcGtMAifwJCTLMg5B
curl: (6) Could not resolve host: 7ejoYH9OCGaVJElV1Vr+fFDt+uw
curl: (6) Could not resolve host: htz29rYkSWwSEix24PbHIPIq1j7YLw4MDJgM9SPX1ipUEQQdEGaXrFdF+tcgcEt7enoMxYY4LPaG
curl: (6) Could not resolve host: g
curl: (6) Could not resolve host: etbW1ra2tiilrCT4GOsm6dvJUFNb5
curl: (6) Could not resolve host: MrTqEkJsNlupP7PBXbc5pwCHw6G5Qim9evXqxMTEhQsXqv7Yubk5p9OJITz0sDcVLHlgG3e73ZVW
curl: (6) Could not resolve host: 88PPaXxj6NbWVlmWNzc319bW5ubm2LmGD7Dcpd5XDatrqZm7uLjodDqxZzE99DlBPpDD4RAEobOz
curl: (6) Could not resolve host: 88qVK5WKjbfd5HZhCWDsu10RxqrIZrNhuUZorOLxeDSBEzs7OxAwMzAwwDZsRi+f3rH2m9
curl: (6) Could not resolve host: fqpCSnOCwSDG8CDXr19fW1srFAoPHz5k1Qb+itB+QhCE0dFRzXux2bMh3d3diUQCfxJVVSE4An7v
curl: (6) Could not resolve host: 9vZ2KOZY6RDHyp5ltnrDip
curl: (6) Could not resolve host: V83FP
curl: (6) Could not resolve host: 4lwzHI2jo6NsO0SMn4Lt45UrV4rFYhUxroqiwK0wd
curl: (6) Could not resolve host: EjyAYwAhRJKk4eHhij58aGhoeHgY76SiKKCK4M8cHh4eGhqqYtarqoqa2
curl: (6) Could not resolve host: viszHonYUwWup6SESv
curl: (6) Could not resolve host: iKaZLLZuw1NjdUv87u4uqPYjp4cmjL75AbNyRW
curl: (6) Could not resolve host: v4Lhs2UOM82pSFGUr7
curl: (6) Could not resolve host: Nj4+DvEX7LOzs7MvXrwQBCESiVS6kmh2b
curl: (6) Could not resolve host: YRsGWJNFUcRUXIfDAaHeUPHJ8F1H+gZZwKFXe8nUMh1FtBJfET3MRK6UiiTnvqITTV18ReDDIIde
curl: (6) Could not resolve host: n4GBgTJXAHNfEYuqqrAhrr1kKjiKjvzS4
curl: (6) Could not resolve host: RxH7jdVVJCp5KgItNT8
curl: (6) Could not resolve host: aCR37twZHR198uQJntXy+byqqoFAYGhoqNSW7UjdTiklh+4WQytqPB7XJwSYg44i3OhB7xbzbaM5
curl: (6) Could not resolve host: sVjsq6++quKNrAWSwzkS1kIej8dfvnyZSqXqMoRUVYUZQY0ykAqFQjabLfNwgx+on7NVTNgaWVhY
curl: (6) Could not resolve host: uHHjxpMnT8ADQgjJ5
curl: (6) Could not resolve host: zzY9PY0VmTCjiK1gAaFlcD2Xy8FrmqHqO62wHKp6WP3eMIgzEomIogh7BPxYNihlfX1dXyffPEga
curl: (6) Could not resolve host: w0bxrAM1nQzfAnu6csJgMBazUo78ZBZ+KjrR1OVUhDGrhBDzRCINYEfp7Ow0nJVsaWAMB2XNMOyi
curl: (6) Could not resolve host: BCiKEovFTEpW7+3twedgyeZoNKqfsJTJlyqVw9f4cqjmwb2BQEAURSihhEs0O50DgYDmcAO3y7y4
curl: (6) Could not resolve host: kWaJg0
curl: (6) Could not resolve host: YrEYDoc1w5pS6nK5NEdUjHovVbBcPczAxW
curl: (6) Could not resolve host: v7aitR8mAli02FdC7qNhmWZRFEsVV8VaavAnq6oqy3Kp6sMm6z61QhWBtIa7ZJQW7j9mArG3S5Zl
curl: (6) Could not resolve host: zRYWEsJMug3F43HNDsDlcl27dk3
curl: (6) Could not resolve host: oAkH5g9bRSaTgdo8WHdEFMXFxUXI5TTJOi5VdRSGgiAIoVBob2+vs7MTRga4nRRFGRkZ0UxFVB6k
curl: (6) Could not resolve host: dKFfPBU9e
curl: (6) Could not resolve host: dHZ2atZENnaj1MkMjwsHBweKong8nlKVWOEcViqJh9amipLJJKxCX375JcjjcDhCoRBcNOlXBEYR
curl: (6) Could not resolve host: w9oQkEaSSqXW19dFUQTFAJaVXC43ODio+UtVpkpTKQcPmGfgB1JV1e12f
curl: (6) Could not resolve host: SPMnmKkiRVEgWVeW5YsXL7IrI
curl: (6) Could not resolve host: 52ES9vT0CIIwMTGhH0bBYFAQBEEQTIY1HLAgNdrpdJZSkyBY+a1NGgBXRSeaeqkikz5b5pgUm4cG
curl: (6) Could not resolve host: cb29vYIgBAKBdDoN1RbgiqGygZUair+Yi+pwOMz7xoJgJvFBlnRxhYXCUCoo14IlFfL5PCzgcMXk
curl: (6) Could not resolve host: LYIgmCwpsKrD7XK5XKWWJhDsyArrcFcvXryoWQmPiKBTVTUWi+nDORRFKXWzoHFqpXa5XC4XiUR8
curl: (6) Could not resolve host: Pl8wGDQ
curl: (6) Could not resolve host: z2KVKoIm9z6fLxaL1XHMNCEwDUOhEBS4rO+H10sVxeNxv99
curl: (6) Could not resolve host: 1efzmYeYbm9vm
curl: (6) Could not resolve host: Y8GCWk5BMkNhqu9XVEcwttLpdMKhshkalcKJqo6V9Kanp2tsygKm8MY3GTOn8aoon89jdD7i9Xrr
curl: (6) Could not resolve host: vkxXDayY5ktAmUBnAa
curl: (6) Could not resolve host: x+OpsU4b1Bwyt86ZY70qcrvdPT09uVxOPaxSCsfnUr2HG
curl: (6) Could not resolve host: 5Uwmo6rqwcEBFteSZdlybZTL5TRV6mvUkT09Peh9yWQygiCIoqgPQKoF84N4A4CBbdjYuwrg3FDj
curl: (6) Could not resolve host: dq1hDcWrAKz09VoHwMlU454bjHi1rG8WqyL4AyKRiOY6aCP9vgaSkxsWIA7D0fxYWibBYLCWLQPg
curl: (6) Could not resolve host: dDrtdrvlq62GBqsiiFjVbAnRKWht8kA2m4XxCVsrUJPQaLm6Xw2OLKzugeNgs21HaufixYul7OGV
curl: (6) Could not resolve host: 4na7a9xBKooCfhHzl1mliiilXq
curl: (6) Could not resolve host: jjidztp790KB4brsO5onhhtpsCoCfy
curl: (6) Could not resolve host: S6iKYJfWyCnQGMAIUXs5
curl: (6) Could not resolve host: znqdjLH27PKNceuNdNrDT157NGCNvxNEZ9Zo
curl: (6) Could not resolve host: rDmuSdIkjoNkMgm9dmr5EEVRarReBgKBMhdWC1URPbxdNa4J+Xye7cFRBWBcrX3SWXwqymazpZpW
curl: (6) Could not resolve host: waxmbzSmvDW4KR+0Z62vr7hSZFmulyW97jT4VASeIUEQ2CnEqiI2rwUCF9mVQlXVvb09NigLKBaL
curl: (6) Could not resolve host: 29vb29vbVS8rmFSot5hDYE6NQSsAxK3U11fUPEDnaAv
curl: (6) Could not resolve host: WKrA+rAFSiksDT6fLxKJwFER7S3szhcLhtbFoFwRjf
curl: (6) Could not resolve host: o1E4oIDVC88WkL8CF0VRrG5q5fN5n89n6LkFV1aNxnR6aJ0LhUK1fEiTc4LmmuWqiJ6o22WOWTnU
curl: (6) Could not resolve host: BqAoyu3bt+fn5zs6OhwOx+bm5uTk5MzMDFtoLxgMvn79mh5W5WttbYX85M7Ozkr7eVQNrw3aVGiK
curl: (6) Could not resolve host: 4RNCstkslGL0eDznzp0jhFBKh4eHvV7v4ODg+++
curl: (6) Could not resolve host: 5ubm
curl: (6) Could not resolve host: ikgkEvPz86FQaGxsrLpPOBHwuVYRp+d2WagGc7kcFNGZnp5G3Q4efqw3FQ6HId8IPQQdHR1wpTkd
curl: (6) Could not resolve host: J28hzVBtATItWAdsNBqVJKlYLGL5S1mW2UxYbEfNRlsVi0W2klOlbG9vj4yMwEbK6XRCzj8aD6Fu
curl: (6) Could not resolve host: Ib44Go36
curl: (6) Could not resolve host: n
curl: (6) Could not resolve host: PpM10Hk8HkmSJiYmwI3k8XjAW+73+wcGBjTR6tlsltVDqVSqXulunFrgqqiOWKaK4JSjr2JHmUJ2
curl: (6) Could not resolve host: bMs+kyZ+HGuxVhVtb2+DAtCEPK2vr0NggmGfNKw
curl: (6) Could not resolve host: amqqo6MD4ybwxL++vg6ZSaxgiqJ0dnbOzs4mEol4PB6Px2
curl: (6) Could not resolve host: hBW+DWH7yOk7y3E4+Xz+008
curl: (6) Could not resolve host: zICnCmlra4N+84QQKCydyWQWFhZ2dnZaW1vZV7rd7gsXLvj9fmhfjYaB3t7era2tjY0N9sVwEORw
curl: (6) Could not resolve host: Tg0WqCJK6dzcHDy+fPmy
curl: (6) Could not resolve host: yubmJtGpnOfPnxNCBEHo6urCi5TSx48fk8MexGWKQSkdGxsrFAqCIBgGFJw9e
curl: (6) Could not resolve host: cHAQJVRVFdQMnI3GxsY2NzedTufVq1cJIRsbG6Io6qs4VxpSweE0O40
curl: (6) Could not resolve host: wRlFnHKwykDn8XhkWWbTg8DTw1rq0FGkMaEYlu3QDDNFUcpJ2kcvpmHaECZrYxcrzZjHtzdJk0lO
curl: (6) Could not resolve host: +XADXR2xwNhFKQWThcZmAmSzWbCo+P1+tMXhHraiJvacU8zIyMjGxkYikcDzECEEjhfs0RkO05qR
curl: (6) Could not resolve host: pqoqjCjNaePJkyeEELvd3tXVRSkdHR1dXFw8UpKVlRV4gC4fFvgiQojX6wUZNGMeTIKSJPGDDudt
curl: (6) Could not resolve host: xgIDHU5FiKDT8OjRI0KIJEnj4+N4ERcUvOL3+2VZvnLlyrGKymlOvF7v0tLStbHuoo4AAANgSURB
curl: (6) Could not resolve host: VGvX7t27Rym12Wzw79bWFsYIkNKOot3dXb2jiFK6urpKCBkcHGxpaclms6urq9j81wR0BWlsgMDT
curl: (6) Could not resolve host: p08JIYIgDA0N6Z
curl: (6) Could not resolve host: FJnTLIRCoYWFBULI
curl: (6) Could not resolve host: xxrUND6fjz29xWKx7u7u1tZWeugEZdVYoVC4e
curl: (52) Empty reply from server
curl: (6) Could not resolve host: giBA6YQjgW
curl: (6) Could not resolve host: PFSqqn7wwQeEEL
curl: (6) Could not resolve host: cNiw9XUmkwmHwxVFx2CwgybGAYqpayrwYxQDRExgVRH0e8O72IqunKaFhy3UEctSXKFbK+4l7Xa7
curl: (6) Could not resolve host: z+czaRAC
curl: (6) Could not resolve host: m8vlIpEIVm7lND9cFdURiytzF4vFYrGo38wawov9NCdcFVFKp6en2YgJ6AJnGAueTCbBpud0OiHu
curl: (6) Could not resolve host: HOqCw5UmbI3IKQVXRXXERrlJmlMblNLf
curl: (6) Could not resolve host: uWezsbE5miuc5kdV1ffff7+lpeUf
curl: (6) Could not resolve host: ZTSRSPziF
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: O4pqh4ctcDgcDsdiuDLncDgcjsVwVcThcDgci+GqiMPhcDgWw1URh8PhcCyGqyIOh8PhWAxXRRwO
curl: (3) unmatched close brace/bracket in URL position 39:
h8OxmP8H33PcSb71qNUAAAAASUVORK5CYII=" }
^

To summerize, the following metho can pass the data correctly:

"$(echo '{ "src": "data:image/jpeg;base64,'$(base64 -i schrodinger.png)'" }' )"

While the following method, which is the official suggested way, failed to do the job:

'{ "src": "data:image/jpeg;base64,'$(base64 -i schrodinger.png)'" }'

Any hints for this problem?

Regards,
HY

Ben Bacarisse

unread,
Jun 10, 2021, 11:25:37 AM6/10/21
to
"hongy...@gmail.com" <hongy...@gmail.com> writes:

> 2. Pass the value of ``--data'' as below failed:
>
> $ curl -x socks5://127.0.0.1:18888 -X POST https://api.mathpix.com/v3/text \
> -H 'app_id: my-app-id' \
> -H 'app_key: my-app-key' \
> -H 'Content-Type: application/json' \
> --data '{ "src": "data:image/jpeg;base64,'$(base64 -i schrodinger.png)'" }'
> {"error":"SyntaxError: Unexpected end of JSON input","error_info": ...

You need ""s round the result of base64. The original was all inside
""s.

--data '{ "src": "data:image/jpeg;base64,'"$(base64 -i schrodinger.png)"'" }'

--
Ben.

hongy...@gmail.com

unread,
Jun 10, 2021, 8:59:51 PM6/10/21
to
Still failed as shown following:

$ curl -x socks5://127.0.0.1:18888 -X POST https://api.mathpix.com/v3/text \
-H 'app_id: xxx' \
-H 'app_key: xxx' \
-H 'Content-Type: application/json' \
--data '{ "src": "data:image/jpeg;base64,'"$(base64 -i schrodinger.png)"'" }'
{"error":"SyntaxError: Unexpected token \n in JSON at position 109","error_info":{"id":"json_syntax","message":"SyntaxError: Unexpected token \n in JSON at position 109"}}

What's wrong with my version above?

HY

Ben Bacarisse

unread,
Jun 10, 2021, 10:27:50 PM6/10/21
to
I thought it was a quoting problem, but it's a newline problem.
Apparently (I know nothing about the details of JSON) JSON strings can't
include newlines. The echo in the first version replaces them with
spaces. If that works, why change it?

If you don't like echo (or the spaces that result) you can use

$(base64 -w0 schrodinger.png)

if your base64 command has that option. Or you could

$(base64 schrodinger.png | tr -d '\n')

--
Ben.

hongy...@gmail.com

unread,
Jun 11, 2021, 1:15:49 AM6/11/21
to
Thank you. Both of the above two methods do the trick.

HY

hongy...@gmail.com

unread,
Jun 11, 2021, 1:25:14 AM6/11/21
to
On Friday, June 11, 2021 at 10:27:50 AM UTC+8, Ben Bacarisse wrote:
> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>
> > On Thursday, June 10, 2021 at 11:25:37 PM UTC+8, Ben Bacarisse wrote:
> >> "hongy...@gmail.com" <hongy...@gmail.com> writes:
> >>
> >> > 2. Pass the value of ``--data'' as below failed:
> >> >
> >> > $ curl -x socks5://127.0.0.1:18888 -X POST https://api.mathpix.com/v3/text \
> >> > -H 'app_id: my-app-id' \
> >> > -H 'app_key: my-app-key' \
> >> > -H 'Content-Type: application/json' \
> >> > --data '{ "src": "data:image/jpeg;base64,'$(base64 -i schrodinger.png)'" }'
> >> > {"error":"SyntaxError: Unexpected end of JSON input","error_info": ...
> >>
> >> You need ""s round the result of base64. The original was all inside
> >> ""s.
> >> --data '{ "src": "data:image/jpeg;base64,'"$(base64 -i schrodinger.png)"'" }'
> >
> > Still failed as shown following:
> >
> > $ curl -x socks5://127.0.0.1:18888 -X POST https://api.mathpix.com/v3/text \
> > -H 'app_id: xxx' \
> > -H 'app_key: xxx' \
> > -H 'Content-Type: application/json' \
> > --data '{ "src": "data:image/jpeg;base64,'"$(base64 -i schrodinger.png)"'" }'
> > {"error":"SyntaxError: Unexpected token \n in JSON at position 109","error_info":{"id":"json_syntax","message":"SyntaxError: Unexpected token \n in JSON at position 109"}}
> >
> > What's wrong with my version above?
> I thought it was a quoting problem, but it's a newline problem.

Why didn't it complain about the error message in my original failed version?

> Apparently (I know nothing about the details of JSON) JSON strings can't
> include newlines. The echo in the first version replaces them with
> spaces. If that works, why change it?

Though my original first version works, it's cumbersome/lengthy to some extent. So, I want to have a more concise solution.

hongy...@gmail.com

unread,
Jun 11, 2021, 1:27:31 AM6/11/21
to
I mean the error message mentioned above here, i.e., the newline problem.

Helmut Waitzmann

unread,
Jun 11, 2021, 4:44:16 AM6/11/21
to
"hongy...@gmail.com" <hongy...@gmail.com>:
>On Friday, June 11, 2021 at 10:27:50 AM UTC+8, Ben Bacarisse wrote:

>> I thought it was a quoting problem, but it's a newline problem.
>>
>
>Why didn't it complain about the error message in my original
>failed version?

In your original version, there weren't any newlines, because you
eliminated them by accident.

Read the docs to learn about the way the shell processes command
substitution ($( ... ), see
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03>)
and field splitting on unquoted expansions (see
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05>),
the way "echo" outputs its arguments (see
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html#tag_20_37_10>),
and the way the shell processes command substitution ($( ... ), see
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03>).

But I don't recommend using "echo":  As soon as there are
backslashes to be placed in the json data, "echo" might interpret
the backslashes, thus corrupting the json data.  Better use the
"base64" "-w" option with its argument 0, as suggested by Ben.

By the way, this is common shell knowledge.  You should really start
learning the shell.  Maybe, you'll have more success doing that
after you'll have learned the "exec" family of functions (see
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html#top>)
of the system interface.

Ben Bacarisse

unread,
Jun 11, 2021, 8:10:42 AM6/11/21
to
"hongy...@gmail.com" <hongy...@gmail.com> writes:

> On Friday, June 11, 2021 at 10:27:50 AM UTC+8, Ben Bacarisse wrote:

>> I thought it was a quoting problem, but it's a newline problem.
>
> Why didn't it complain about the error message in my original failed
> version?

In that version (IIRC) the echo command substitution cases another round
of word splitting that replaces newlines with spaces.

--
Ben.

hongy...@gmail.com

unread,
Jun 11, 2021, 9:02:54 AM6/11/21
to
If so, why the following version doesn't work?:

--data '{ "src": "data:image/jpeg;base64,'$(base64 schrodinger.png |tr '\n' ' ')'" }'

HY

Ben Bacarisse

unread,
Jun 11, 2021, 4:45:45 PM6/11/21
to
"hongy...@gmail.com" <hongy...@gmail.com> writes:

> On Friday, June 11, 2021 at 8:10:42 PM UTC+8, Ben Bacarisse wrote:
>> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>>
>> > On Friday, June 11, 2021 at 10:27:50 AM UTC+8, Ben Bacarisse wrote:
>>
>> >> I thought it was a quoting problem, but it's a newline problem.
>> >
>> > Why didn't it complain about the error message in my original failed
>> > version?
>> In that version (IIRC) the echo command substitution cases another round
>> of word splitting that replaces newlines with spaces.
>
> If so, why the following version doesn't work?:
>
> --data '{ "src": "data:image/jpeg;base64,'$(base64 schrodinger.png |tr
> '\n' ' ')'" }'

Because the spaces appear in different contexts.

Let's simplify:
$ cat lines
abc
def
ghi
$ printf "[%s]" '{'$(tr -d '\n' <lines)'}'
[{abcdefghi}]

After the format, printf gets one argument.

$ printf "[%s]" '{'$(tr '\n' ' ' <lines)'}'
[{abc][def][ghi][}]

printf gets four arguments. This is what you latest example does. The
--data option is not followed by one argument but by many depending on
how many lines the base64 encoding contains.

$ printf "[%s]" "$(echo '{'$(cat lines)'}')"
[{abc def ghi}]

printf gets one argument with newlines (except for the last) replaced by
the shell's word separator.

You need to find way to develop the skills to investigate these
questions for yourself.

--
Ben.

hongy...@gmail.com

unread,
Jun 11, 2021, 7:12:01 PM6/11/21
to
Really. It's the heart of learning. In fact, I've tried to use `diff' and process substitution `<( echo ... )' to compare the different methods, but failed to dig out any valuable clues.

HY

Janis Papanagnou

unread,
Jun 11, 2021, 8:12:47 PM6/11/21
to
"Finding ways to develop skills" has nothing to do with diff, or echo,
or process substitution, or other "different [technical] methods".

I read it as a meta-suggestion and would interpret it as "learn how to
fish" as opposed to "try all the fishing tools until it somehow works".

Something like decomposing the task you have in small pieces and learn
how these pieces behave, then once you have confidence about the parts
compose the more complex code patterns.

Janis

Kaz Kylheku

unread,
Jun 11, 2021, 9:27:07 PM6/11/21
to
On 2021-06-11, hongy...@gmail.com <hongy...@gmail.com> wrote:
> Really. It's the heart of learning.

Given that you've been posting since 2009 and still struggle
with absolute basics, you might want to be to be looking for the path to
the "heart of retaining".

What's the use of learning, if it is gone the next day?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Kenny McCormack

unread,
Jun 12, 2021, 6:25:36 AM6/12/21
to
In article <202106111...@kylheku.com>,
Kaz Kylheku <563-36...@kylheku.com> wrote:
>On 2021-06-11, hongy...@gmail.com <hongy...@gmail.com> wrote:
>> Really. It's the heart of learning.
>
>Given that you've been posting since 2009 and still struggle
>with absolute basics, you might want to be to be looking for the path to
>the "heart of retaining".
>
>What's the use of learning, if it is gone the next day?

Ya know... Usenetters like to make fun of:

1) People who post via Google Groups
and
2) People like hongy

But, if you get right down to it, if it weren't for one or both of these
kind of posters, we'd get no traffic here at all.

Now, there was a time (like, 4 decades ago), when zero traffic was actually
sort of the goal (because we had enough traffic that we knew we'd never
achieve that goal), but those days are now gone.

So, be careful what you wish for...

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/GodDelusion

Helmut Waitzmann

unread,
Jun 12, 2021, 1:58:34 PM6/12/21
to
"hongy...@gmail.com" <hongy...@gmail.com>:

>In fact, I've tried to use `diff' and process substitution `<( echo
>... )' to compare the different methods, but failed to dig out any
>valuable clues.

The problem is, that you apparently don't know what the shell does: 
The shell reads and parses its commandline.  Then, when it is going
to start a utility (in shell grammar speech: a simple command) it
has to construct an “execve” (see
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html#top>)
argument vector out of the command line.  Part of this construction
is field splitting, which occurs when expansions of shell parameters
(like “$variable”) or of command substitution (like “$(base64 …)”)
are used without double quotes.

You also apparently don't know, what the “echo” utility does.  If
you knew it, you wouldn't use it in your use case.  But as long as
you don't understand, what an “execve” argument vector is, you won't
understand, that “echo” does not just copy its shell command line to
standard output, because “echo” will never see such a thing like a
shell command line.  “echo” will process the elements of its given
“execve” argument vector, writing the results to standard output,
separated by single spaces.

And you apparently don't know, what the “base64” utility does.  If
you knew it, you would have given it the “-w” “0” parameters (like
Ben suggested).

First learn unix or linux – here: how utilities are started by means
of the “exec” family of functions –, then come back to the shell and
learn, how it constructs an “execve” argument vector out of its
commandline using quoted and unquoted variable expansions and quoted
and unquoted command substitutions.

As long as you don't know that, you'll never dig out any valuable
clues.

hongy...@gmail.com

unread,
Jun 12, 2021, 10:18:45 PM6/12/21
to
Thank you very much for your, as always, profound and thorough analysis.

Helmut Waitzmann

unread,
Jun 13, 2021, 7:19:28 PM6/13/21
to
Helmut Waitzmann <nn.th...@xoxy.net>:

>The shell reads and parses its commandline.  Then, when it is going
>to start a utility (in shell grammar speech: a simple command) it
>has to construct an “execve” (see
><https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html#top>)
>argument vector out of the command line.  Part of this construction
>is field splitting, which occurs when expansions of shell
>parameters (like “$variable”) or of command substitution (like
>“$(base64 …)”) are used without double quotes.

[…]

>But as long as you don't understand, what an “execve” argument
>vector is, you won't understand, that “echo” does not just copy its
>shell command line to standard output, because “echo” will never
>see such a thing like a shell command line.  “echo” will process
>the elements of its given “execve” argument vector, writing the
>results to standard output, separated by single spaces.

[…]

>First learn unix or linux – here: how utilities are started by
>means of the “exec” family of functions –, then come back to the
>shell and learn, how it constructs an “execve” argument vector out
>of its commandline using quoted and unquoted variable expansions
>and quoted and unquoted command substitutions.

To get a more thorough insight into “execve” you might read the book


Maurice J. Bach: The Design Of The Unix Operating System

Prentice-Hall International, London, 1986

which explains the basics.  It even has a chapter about the shell. 
Maybe you could borrow it from a library.  Probably there are other
good books (which I don't know of), too.

The EXAMPLE section of the execve(2) manual page shows two small
programs (written in the C programming language), which demonstrate
the use and the purpose of the “execve” argument vector.

hongy...@gmail.com

unread,
Jun 13, 2021, 7:45:10 PM6/13/21
to
On Monday, June 14, 2021 at 7:19:28 AM UTC+8, Helmut Waitzmann wrote:
> Helmut Waitzmann <nn.th...@xoxy.net>:
> >The shell reads and parses its commandline. Then, when it is going
> >to start a utility (in shell grammar speech: a simple command) it
> >has to construct an “execve” (see
> ><https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html#top>)
> >argument vector out of the command line. Part of this construction
> >is field splitting, which occurs when expansions of shell
> >parameters (like “$variable”) or of command substitution (like
> >“$(base64 …)”) are used without double quotes.
> […]
> >But as long as you don't understand, what an “execve” argument
> >vector is, you won't understand, that “echo” does not just copy its
> >shell command line to standard output, because “echo” will never
> >see such a thing like a shell command line. “echo” will process
> >the elements of its given “execve” argument vector, writing the
> >results to standard output, separated by single spaces.
> […]
> >First learn unix or linux – here: how utilities are started by
> >means of the “exec” family of functions –, then come back to the
> >shell and learn, how it constructs an “execve” argument vector out
> >of its commandline using quoted and unquoted variable expansions
> >and quoted and unquoted command substitutions.
> To get a more thorough insight into “execve” you might read the book
>
>
> Maurice J. Bach: The Design Of The Unix Operating System
>
> Prentice-Hall International, London, 1986

Thank you. I'll try to find and read it.

>
> which explains the basics. It even has a chapter about the shell.
> Maybe you could borrow it from a library. Probably there are other
> good books (which I don't know of), too.
>
> The EXAMPLE section of the execve(2) manual page shows two small
> programs (written in the C programming language), which demonstrate
> the use and the purpose of the “execve” argument vector.

Thank you. I'll try to read them.
0 new messages